problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02719
u985835425
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['N, K = map(int,input().split())\nmin(N%K,K-N%K)', 'N, K = map(int,input().split())\nprint(min(N%K,K-N%K))']
['Wrong Answer', 'Accepted']
['s715178842', 's505449233']
[2940.0, 3060.0]
[17.0, 43.0]
[46, 53]
p02719
u986889396
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['str = input().split()\nn = int(str[0])\nk = int(str[1])\nt = n%k\nother = abs(k-t)\nprint(min(t,other))\nif t <= other:\n print(t)\nelse:\n print(other)', 'str = input().split()\na1 = int(str[0])\na2 = int(str[1])\nif a1 >= a2:\n a1 = a2%a1\nif a1 < a2-a1:\n print(a1)\nelse:\n print(a2-a1)', 'str = input().split()\nn = int(str[0])\nk = int(str[1])\nt = n%k\nother = abs(k-t)\nprint(min(t,other))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s154312188', 's234178883', 's692616309']
[3060.0, 2940.0, 2940.0]
[17.0, 18.0, 17.0]
[149, 135, 98]
p02719
u987326700
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['n,k = map(int,input().split())\n\nif abs(n-k)>n:\n while True:\n n -= k\n if n<0:\n break\n \nprint(abs(n))\n ', 'n,k = map(int,input().split())\nnum = 0\nwhile True:\n\tnum = n-k\n if num < 0:\n print(abs(num))', 'n,k = map(int,input().split())\n\n\nif abs(n-k)>n:\n print(n)\nelse:\n while True:\n n -= k\n if n<0:\n break\n print(n)\n \n', 'n,k = map(int,input().split())\n\nd = n//k\n\nn = n - d*n\n\nif abs(n-k)>n:\n print(n)\nelse:\n print(abs(n-k))\n \n', 'n,k = map(int,input().split())\n\nif n>k:\n n = n%k\n\nans = min(n,abs(n-k))\n\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s011047203', 's211705211', 's831205206', 's956282717', 's122297138']
[2940.0, 2940.0, 2940.0, 2940.0, 2940.0]
[17.0, 18.0, 2104.0, 17.0, 17.0]
[119, 99, 128, 108, 84]
p02719
u989345508
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['from fractions import gcd\nn,k=map(int,input().split())\nif k==1:\n print(0)\nelse:\n print(gcd(n,k))\n', 'n,k=map(int,input().split())\nn=n%k\nprint(min(n,k-n))\n']
['Wrong Answer', 'Accepted']
['s762581727', 's174212877']
[5176.0, 2940.0]
[35.0, 18.0]
[103, 53]
p02719
u991619971
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['#K = int(input())\nN,K = map(int,input().split())\n#N = int(input())\n#A = list(map(int,input().split()))\nflag=True\nc=N\nif N%K==0:\n print(0)\nelse:\n l=N//K\n while flag==True:\n\n N=abs(l-K)\n if c <= N:\n flag=False\n else:\n c=N\nprint(c)\n', '#K = int(input())\nN,K = map(int,input().split())\n#N = int(input())\n#A = list(map(int,input().split()))\nflag=True\nc=N\nif N%K==0:\n print(0)\n exit()\nelse:\n l=N//K\n N-=l*K\n while flag==True:\n\n N=abs(N-K)\n if c <= N:\n flag=False\n else:\n c=N\nprint(c)\n']
['Wrong Answer', 'Accepted']
['s136573160', 's427420919']
[2940.0, 2940.0]
[17.0, 17.0]
[281, 303]
p02719
u992951814
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['n,k = map(int,input().split())\nif(k==1):\n print(0)\nelse:\n while(len(n)>1):\n n = n//k\n t = n//k\n for i in range(t):\n n = abs(n-k)\n if(n < abs(k-n)):\n print(n)\n else:\n print(abs(k-n))', 'n,k = map(int,input().split())\nif(k==1):\n print(0)\nelse:\n t = n%k\n if(n < abs(k-n)):\n print(n)\n else:\n print(abs(k-n))\n ', 'n,k = map(int,input().split())\nt = n%k\nif(n < abs(k-n)):\n print(n)\nelse:\n print(abs(k-n))', 'N, K = map(int,input().split())\nt = N%K\nif (K - t) >= t:\n print(t)\nelse:\n print(K - t)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s164789872', 's284389644', 's577129019', 's587127439']
[3060.0, 2940.0, 2940.0, 2940.0]
[17.0, 18.0, 17.0, 17.0]
[199, 130, 91, 92]
p02719
u995163736
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['n, k = map(int, input().split())\n\nif n % k == 0:\n print(0)\nelse: \n ans = n % k\n while ans > abs(n-k):\n n = abs(n - k)\n ans = min(n, ans)\n print(ans)', 'n, k = map(int, input().split())\n\nif n % k == 0:\n print(0)\nelse: \n ans = n % k\n #print(ans)\n while ans > k//2:\n n = abs(ans - k)\n ans = min(n, ans)\n print(ans)']
['Wrong Answer', 'Accepted']
['s618374325', 's405482473']
[8988.0, 8912.0]
[30.0, 30.0]
[158, 170]
p02719
u995419623
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['n,k = map(int,input().split())\nprint(min(n%k,k-n%k)', 'n,k = map(int,input().split())\nprint(min(n%k,k-n%k))']
['Runtime Error', 'Accepted']
['s584198985', 's960220552']
[2940.0, 2940.0]
[17.0, 17.0]
[51, 52]
p02719
u998350437
2,000
1,048,576
Given any integer x, Aoki can do the operation below. Operation: Replace x with the absolute difference of x and K. You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
['n,k=map(int,input().split())\nn=n%k\nprint(n)', 'k=int(input())\n\na=[]\ni=1\nd=0\nwhile True:\n if len(str(i))==1:\n a.append(i)\n elif len(str(i))==2:\n I=str(i)\n c=abs(int(I[0])-int(I[1]))\n if c<=1:\n a.append(i) \n \n elif len(str(i))==3:\n I=str(i)\n for j in range(2):\n c=abs(int(I[j])-int(I[j+1]))\n if c<=1:\n d=d+1\n if d==2:\n a.append(i)\n d=0\n \n elif len(str(i))==4:\n I=str(i)\n for j in range(3):\n c=abs(int(I[j])-int(I[j+1]))\n if c<=1:\n d=d+1\n if d==3:\n a.append(i) \n d=0\n \n elif len(str(i))==5:\n I=str(i)\n for j in range(4):\n c=abs(int(I[j])-int(I[j+1]))\n if c<=1:\n d=d+1\n if d==4:\n a.append(i) \n d=0\n \n elif len(str(i))==6:\n I=str(i)\n for j in range(5):\n c=abs(int(I[j])-int(I[j+1]))\n if c<=1:\n d=d+1\n if d==5:\n a.append(i)\n d=0\n \n elif len(str(i))==7:\n I=str(i)\n for j in range(6):\n c=abs(int(I[j])-int(I[j+1]))\n if c<=1:\n d=d+1\n if d==6:\n a.append(i)\n \n d=0 \n \n elif len(str(i))==8:\n I=str(i)\n for j in range(7):\n c=abs(int(I[j])-int(I[j+1]))\n if c<=1:\n d=d+1\n if d==7:\n a.append(i)\n \n d=0 \n \n i=i+1\n if i==10000000:\n break\n\nprint(a[k-1])', 'n,k=map(int,input().split())\nn=n%k\na=min(n,abs(n-k))\nprint(a)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s134295644', 's153994084', 's143012066']
[2940.0, 3192.0, 2940.0]
[17.0, 18.0, 18.0]
[43, 1600, 61]
p02720
u023229441
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['n=int(input())\nif n<=10 : \n print(n)\n exit()\n \nans=[0 for i in range(10**5+21)]\nQ=[0,1,2,3]\ndef li(x):\n if x==0 : return [0,1]\n if x==9 : return [8,9]\n return [x-1,x,x+1]\n\nnow=0\nfor q in Q:\n W=[i for i in range(10)] if q==0 else li(q)\n for w in W:\n E=[i for i in range(10)] if [q,w]==[0,0] else li(w)\n for e in E:\n R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)\n for r in R:\n T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)\n for t in T:\n Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)\n for y in Y:\n U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)\n for u in U:\n I=[i for i in range(10)] if [q,w,e,r,t,y,u]==[0,0,0,0,0,0,0] else li(u)\n for i in I:\n O=[i for i in range(10)] if [q,w,e,r,t,y,u,i]==[0,0,0,0,0,0,0,0] else li(i)\n for o in O:\n P=[i for i in range(10)] if [q,w,e,r,t,y,u,i,o]==[0,0,0,0,0,0,0,0,0,0] else li(o)\n for p in P:\n \n ans[now]= 10**9*q + 10**8*w + 10**7*e + 10**6*r + 10**5*t + 10**4*y + 1000*u + 100*i + 10*o + p\n \n if now>=10**5+2 : break\n now+=1\n\nans=list(set(ans))\nans.sort()\nprint(ans[n])\n\n', 'n=int(input())\nans=[0 for i in range(10**5+21)]\nQ=[0,1,2,3]\ndef li(x):\n if x==0 : return [0,1]\n if x==9 : return [8,9]\n return [x-1,x,x+1]\n\nnow=0\nfor q in Q:\n W=[i for i in range(10)] if q==0 else li(q)\n for w in W:\n E=[i for i in range(10)] if [q,w]==[0,0] else li(w)\n for e in E:\n R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)\n for r in R:\n T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)\n for t in T:\n Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)\n for y in Y:\n U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)\n for u in U:\n I=[i for i in range(10)] if [q,w,e,r,t,y,u]==[0,0,0,0,0,0,0] else li(u)\n for i in I:\n O=[i for i in range(10)] if [q,w,e,r,t,y,u,i]==[0,0,0,0,0,0,0,0] else li(i)\n for o in O:\n P=[i for i in range(10)] if [q,w,e,r,t,y,u,i,o]==[0,0,0,0,0,0,0,0,0] else li(o)\n for p in P:\n \n ans[now]= 10**9*q + 10**8*w + 10**7*e + 10**6*r + 10**5*t + 10**4*y + 1000*u + 100*i + 10*o + p\n \n if now>=10**5+2 : break\n now+=1\n\n\nprint(ans[n])']
['Wrong Answer', 'Accepted']
['s023744789', 's632343498']
[13556.0, 7388.0]
[172.0, 151.0]
[1333, 1265]
p02720
u024768467
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['# solution\nk=int(input())\n\nfrom collections import deque\ntodo = deque([i for i in range(1, 10)])\ncount = 0\n\nwhile len(todo) > 0:\n value = todo.popleft()\n seen.append(value)\n value_digit1 = value % 10\n count += 1\n if count == k:\n print(value)\n break\n if value_digit1==0:\n todo.append(10*value)\n todo.append(10*value+1)\n elif value_digit1==9:\n todo.append(10*value+8)\n todo.append(10*value+9)\n else:\n todo.append(10*value+value_digit1-1)\n todo.append(10*value+value_digit1)\n todo.append(10*value+value_digit1+1)', '# solution\nk=int(input())\n\nfrom collections import deque\ntodo = deque([i for i in range(1, 10)])\ncount = 0\n\nwhile len(todo) > 0:\n value = todo.popleft()\n value_digit1 = value % 10\n count += 1\n if count == k:\n print(value)\n break\n if value_digit1==0:\n todo.append(10*value)\n todo.append(10*value+1)\n elif value_digit1==9:\n todo.append(10*value+8)\n todo.append(10*value+9)\n else:\n todo.append(10*value+value_digit1-1)\n todo.append(10*value+value_digit1)\n todo.append(10*value+value_digit1+1)']
['Runtime Error', 'Accepted']
['s881638068', 's918936486']
[3444.0, 11916.0]
[98.0, 129.0]
[596, 573]
p02720
u024782094
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import itertools\nk=int(input())\nl=[[1,2,3,4,5,6,7,8,9]]\nfor _ in range(10):\n a=[]\n for i in range(len(l[-1])):\n L=l[-1][i]\n if L%10==9:\n a.append(L*10+8)\n a.append(L*10+9)\n elif L%10==0:\n a.append(L*10+0)\n a.append(L*10+1)\n else:\n a.append(L*10+L%10-1)\n a.append(L*10+L%10)\n a.append(L*10+L%10+1)\n l.append(a)\nprint(sorted(set(list(itertools.chain.from_iterable(l))))[k-1])', 'from collections import deque\nk=int(input())\nl=deque([1,2,3,4,5,6,7,8,9])\nfor i in range(k-1):\n d=l.popleft()\n a=d%10\n if a!=0:\n l.append(d*10+a-1)\n l.append(d*10+a)\n if a!=9:\n l.append(d*10+a+1)\nprint(l.popleft())']
['Time Limit Exceeded', 'Accepted']
['s452804470', 's779334334']
[1674640.0, 11956.0]
[2196.0, 108.0]
[425, 225]
p02720
u025287757
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\ndef dfs(s):\n if len(s)<10:\n for i in range(-1, 2, 1):\n s+str(min(9, max(0, int(s[-1])+i)))\n return dfs(s)\n else:\n return s\nS = []\nfor i in range(10):\n S.append(dfs(str(i)))\n ', 'import sys\nsys.setrecursionlimit(10**6)\n\nk = int(input())\nS = []\ndef dfs(s):\n if len(s)<10:\n for i in range(-1, 2, 1):\n a = str(min(9, max(0, int(s[0])+i)))+s\n S.append(a)\n dfs(a)\n\nfor i in range(10):\n S.append(i)\n dfs(str(i))\nS = sorted(set([int(s) for s in S]))\nprint(S[k])']
['Runtime Error', 'Accepted']
['s849893242', 's489144811']
[3924.0, 47924.0]
[75.0, 504.0]
[211, 296]
p02720
u038815010
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['n=int(input())\na=list(map(int,input().split()))\nfrom collections import Counter\nd=Counter(a)\nimport math\ndef cmb(n,r):\n f = math.factorial\n return int(f(n) // f(r) // f(n-r))\ndef combination(n, r):\n a = 1\n b = 1\n for i in range(r):\n a *= (n - i)\n b *= (i + 1)\n return a // b\ne={}\ndd=0\nfor i,j in d.items():\n dd+=combination(j, 2)\n e[i]=combination(j-1, 1)\n\nfor i in a:\n print(dd-e[i])\n \n', 'k=int(input())\nif k<=9:\n print(k)\n exit()\na=[1,2,3,4,5,6,7,8,9]\ncnt=9\nwhile True:\n q=[]\n for i in a:\n for j in range(10):\n if abs(int(str(i)[-1])-j)<=1:\n cnt+=1\n if cnt==k:\n print(int(str(i)+str(j)))\n exit()\n q.append(int(str(i)+str(j))) \n a=list(sorted(set(q)))\n']
['Runtime Error', 'Accepted']
['s688420219', 's666417379']
[3064.0, 8140.0]
[18.0, 313.0]
[429, 386]
p02720
u054514819
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["K = int(input())\n\nmin_r = 0\nmax_r = 12\n\ndef count(idx, n):\n if idx==0:\n return 1\n if n==0:\n return count(idx-1, 1)+count(idx-1, 0)\n elif n==9:\n return count(idx-1, 9)+count(idx-1, 8)\n else:\n return count(idx-1, n-1)+count(idx-1, n)+count(idx-1, n+1)\n\nlists = []\ndef count_2(idx, n, list_b):\n lis = list_b[:]\n lis.append(str(n))\n if idx==0:\n lists.append(int(''.join(lis)))\n return 1\n if n==0:\n count_2(idx-1, 1, lis)\n count_2(idx-1, 0, lis)\n elif n==9:\n count_2(idx-1, 9, lis)\n count_2(idx-1, 8, lis)\n else:\n count_2(idx-1, n-1, lis)\n count_2(idx-1, n, lis)\n count_2(idx-1, n+1, lis)\n\nd = 0\nnow = 0\nwhile 1:\n p = sum([count(d, i) for i in range(1, 10)])\n now += p\n if now>K:\n now -= p\n break\n d += 1\n\nsump = 0\nfor i in range(1, 10):\n sump_old = sump\n sump += count(d, i)\n if sump+now>K:\n break\ncount_2(d, i, [])\nprint(lists[K-now-sump_old+1])", 'K = int(input())\nfrom collections import deque\n\nqueue = deque()\nfor i in range(1, 10):\n queue.appendleft(i)\n\nfor _ in range(K-1):\n p = queue.pop()\n if p%10!=0:\n queue.appendleft(p*10+p%10-1)\n queue.appendleft(p*10+p%10)\n if p%10!=9:\n queue.appendleft(p*10+p%10+1)\n\nprint(queue.pop())\n']
['Runtime Error', 'Accepted']
['s769042221', 's648897608']
[3684.0, 11908.0]
[98.0, 127.0]
[1005, 313]
p02720
u064434060
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import headq\n\nheap=[]\nN = input()\nfor i in range(10):\n heapq.heappush(heap,i)\nprint(heap)\n', 'import heapq\n \nheap=[]\nN = int(input())\nfor i in range(1,10):\n heapq.heappush(heap,i)\nfor i in range(N):\n x = heapq.heappop(heap)\n if x%10!=0:\n heapq.heappush(heap,10*x+(x%10)-1)\n heapq.heappush(heap,10*x+(x%10))\n if x%10!=9:\n heapq.heappush(heap,10*x+(x%10)+1)\n \nprint(x)']
['Runtime Error', 'Accepted']
['s276755181', 's124102687']
[3064.0, 11728.0]
[18.0, 196.0]
[91, 284]
p02720
u065578867
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\na[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nfor i in range(k):\n if a[i] % 10 != 0:\n a.append(10*a[i] + a[i] % 10 - 1)\n a.append(10*a[i] + a[i] % 10)\n if a[i] % 10 != 9:\n a.append(10*a[i] + a[i] % 10 + 1)\n\nprint(a[k - 1])\n', 'k = int(input())\na = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nfor i in range(k):\n if a[i] % 10 != 0:\n a.append(10*a[i] + a[i] % 10 - 1)\n a.append(10*a[i] + a[i] % 10)\n if a[i] % 10 != 9:\n a.append(10*a[i] + a[i] % 10 + 1)\n\nprint(a[k - 1])\n']
['Runtime Error', 'Accepted']
['s453451385', 's298160640']
[3060.0, 15784.0]
[17.0, 151.0]
[253, 250]
p02720
u070201429
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["k = int(input())\nl = ['1','2','3','4','5','6','7','8','9']\nlf = ['1','2','3','4','5','6','7','8','9']\nsum = 9\nwhile sum < k:\n lff = []\n for i in lf:\n if i[-1] == [0]:\n lff.append(i+'0')\n lff.append(i+'1')\n elif i[-1] == [9]:\n lff.append(i+'8')\n lff.append(i+'9')\n else:\n lff.append(i+str(int(i[-1]-1)))\n lff.append(i+str(int(i[-1])))\n lff.append(i+str(int(i[-1]+1)))\n lf = lff\n l += lff\nprint(l[k-1])", "k = int(input())\nl = ['1','2','3','4','5','6','7','8','9']\nlf = l.copy()\nsum = 9\nwhile sum < k:\n lff = []\n for i in lf:\n if i[-1] == '0':\n lff.append(i+'0')\n lff.append(i+'1')\n elif i[-1] == '9':\n lff.append(i+'8')\n lff.append(i+'9')\n else:\n lff.append(i+str(int(i[-1])-1))\n lff.append(i+str(int(i[-1])))\n lff.append(i+str(int(i[-1])+1))\n lf = lff\n l += lff\n sum += len(lff)\nprint(int(l[k-1]))"]
['Runtime Error', 'Accepted']
['s161746179', 's113030118']
[3064.0, 18296.0]
[17.0, 163.0]
[510, 506]
p02720
u072717685
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["import sys\nsys.setrecursionlimit(10**6)\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\nfrom math import log10,ceil\ndef main():\n k = int(input())\n k2 = ceil(k / 10)\n def getlun(n):\n lunluns.append(n)\n ns = str(n)\n print(lunluns)\n if len(ns) > k2:\n pass\n else:\n ns1 = int(ns[0])\n if ns1 != 0:\n l1 = ns[0] + ns\n getlun(int(l1))\n if ns1 > 1:\n l2 = str(ns1 - 1) + ns\n getlun(int(l2))\n if ns1 < 9:\n l3 = str(ns1 + 1) + ns\n getlun(int(l3))\n lunluns = []\n for i1 in range(0, 10):\n getlun(i1)\n lunluns.sort()\n print(lunluns[k])\n\nif __name__ == '__main__':\n main()", "import sys\nsys.setrecursionlimit(10**6)\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\nfrom math import ceil, log\ndef main():\n k = int(input())\n k2 = int(log(ceil(k / 10), 3)) + 1\n def getlun(n, keta, last):\n lunluns.append(n)\n if keta > k2:\n pass\n else:\n l1 = n * 10 + last\n getlun(l1, keta + 1, last)\n if last > 0:\n l2 = n * 10 + last - 1\n getlun(l2, keta + 1, last - 1)\n if last < 9:\n l3 = n * 10 + last + 1\n getlun(l3, keta + 1, last + 1)\n lunluns = []\n for i1 in range(1, 10):\n getlun(i1, 0, i1)\n lunluns.sort()\n print(lunluns[k-1])\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s812734288', 's560060939']
[141848.0, 38380.0]
[1376.0, 266.0]
[772, 748]
p02720
u075012704
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["from itertools import product\nK = int(input())\n\nans = []\nfor l in range(10):\n for s in range(1, 10):\n for pattern in product([-1, 0, 1], repeat=l):\n X = [s]\n for p in pattern:\n if not (0 <= X[-1] + p <= 9):\n break\n X.append(X[-1] + p)\n else:\n ans.append(''.join(map(str, X)))\n\nans.sort()\nprint(ans[K - 1])\n", "from itertools import product\nK = int(input())\n\nans = []\nfor l in range(10):\n for s in range(1, 10):\n for pattern in product([-1, 0, 1], repeat=l):\n X = [s]\n for p in pattern:\n if not (0 <= X[-1] + p <= 9):\n break\n X.append(X[-1] + p)\n else:\n ans.append(int(''.join(map(str, X))))\n\nans.sort()\nprint(ans[K - 1])\n"]
['Wrong Answer', 'Accepted']
['s965417070', 's300572695']
[17832.0, 11036.0]
[1093.0, 1237.0]
[413, 418]
p02720
u075595666
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]\nimport heapq\nheapq.heapify(a)\ncnt = 18\nc = 1\nwhile True:\n if cnt > 10**5:\n break\n for i in a:\n if len(str(i)) == c:\n m = i//10**(c-1)\n if i//10**(c-1) == 1:\n heapq.heappush(a,i+10**c*(i//10**(c-1)))\n heapq.heappush(a,i+10**c*(i//10**(c-1)+1))\n cnt += 2\n for j in range(10-c):\n heapq.heappush(a,i+10**c*(10**(j+1)))\n cnt += 1\n elif i//10**(c-1) == 9:\n heapq.heappush(a,i+10**c*(i//10**(c-1)-1))\n heapq.heappush(a,i+10**c*(i//10**(c-1)))\n cnt += 2\n else:\n heapq.heappush(a,i+10**c*(i//10**(c-1)-1))\n heapq.heappush(a,i+10**c*(i//10**(c-1)))\n heapq.heappush(a,i+10**c*(i//10**(c-1)+1))\n cnt += 3\n c += 1\n\nk = int(input())\n#a = set(a)\n#a = list(a)\nfor i in range(k):\n heapq.heappop(a)\nprint(heapq.heappop(a))', 'a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]\nimport heapq\nheapq.heapify(a)\ncnt = 18\nc = 1\nwhile True:\n if cnt > 10**5:\n break\n for i in a:\n if len(str(i)) == c:\n m = i//10**(c-1)\n if i//10**(c-1) == 1:\n heapq.heappush(a,i+10**c*(i//10**(c-1)))\n heapq.heappush(a,i+10**c*(i//10**(c-1)+1))\n cnt += 2\n for j in range(10-c):\n heapq.heappush(a,i+10**c*(10**(j+1)))\n cnt += 1\n elif i//10**(c-1) == 9:\n heapq.heappush(a,i+10**c*(i//10**(c-1)-1))\n heapq.heappush(a,i+10**c*(i//10**(c-1)))\n cnt += 2\n else:\n heapq.heappush(a,i+10**c*(i//10**(c-1)-1))\n heapq.heappush(a,i+10**c*(i//10**(c-1)))\n heapq.heappush(a,i+10**c*(i//10**(c-1)+1))\n cnt += 3\n c += 1\n\nk = int(input())\n#a = set(a)\n#a = list(a)\nfor i in range(k-1):\n heapq.heappop(a)\nprint(heapq.heappop(a))']
['Wrong Answer', 'Accepted']
['s083932874', 's549172628']
[12352.0, 12352.0]
[464.0, 469.0]
[916, 918]
p02720
u078181689
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\n\nnumset = {i for i in range(1,10)}\nflag = False\ncount = len(numset)\nif count >= k:\n flag = True\narr = [numset]\nindex = 0\n\nwhile not flag:\n beforeset = arr[index]\n tmpset = set()\n for i in beforeset:\n tail = str(i)[-1]\n if tail == "0":\n tmpset.add(int(str(i)+str(0)))\n tmpset.add(int(str(i)+str(1)))\n elif tail == "9":\n tmpset.add(int(str(i)+str(8)))\n tmpset.add(int(str(i)+str(9)))\n else:\n tmpset.add(int(str(i)+str(int(tail))))\n tmpset.add(int(str(i)+str(int(tail)+1)))\n tmpset.add(int(str(i)+str(int(tail)-1)))\n count += len(tmpset)\n if count >= k:\n flag = True\n arr.append(tmpset)\n index += 1\n \ntotalarr = []\nfor tmpset in arr:\n totalarr += list(tmpset)\n \ntotalarr.sort()\nprint(totalarr[k])', 'k = int(input())\n\nfrom collection import deque\nqueue = deque(range(1,10))\ncount = 0\nwhile count < k:\n count += 1\n tmp = queue.popleft()\n tail = tmp%10\n if tail != 0:\n queue.append(10*tmp+tail-1)\n queue.append(10*tmp)\n if tail != 9:\n queue.append(10*tmp+tail+1)\n\nprint(tmp)', 'k = int(input())\nfrom collections import deque\nqueue = deque(range(1,10))\ncount = 0\n\nwhile count < k:\n count += 1\n tmp = deque.popleft()\n tail = tmp % 10\n if tail!=0:\n deque.append(tmp*10+tail-1)\n deque.append(tmp*10+tail)\n if tail!=9:\n deque.append(tmp*10+tail+1)\n \nprint(tmp)', 'k = int(input())\nfrom collections import deque\nqueue = deque(range(1,10))\ncount = 0\n\nwhile count < k:\n count += 1\n tmp = queue.popleft()\n tail = tmp % 10\n if tail!=0:\n queue.append(tmp*10+tail-1)\n queue.append(tmp*10+tail)\n if tail!=9:\n queue.append(tmp*10+tail+1)\n \nprint(tmp)']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s099391033', 's435545136', 's463182007', 's303119406']
[20236.0, 3064.0, 3316.0, 11956.0]
[294.0, 17.0, 21.0, 125.0]
[855, 284, 290, 290]
p02720
u089142196
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K=int(input())\nx=[[0] for _ in range(11)]\ny=[ 0 for _ in range(11)]\n\nx[1]=[1,2,3,4,5,6,7,8,9]\ny[1]=9\n\nfor i in range(2,11):\n x[i].pop()\n for num in x[i-1]:\n last = num%10\n if last==0:\n x[i].append(10*num)\n x[i].append(10*num+1)\n y[i] +=2\n elif last==9:\n x[i].append(10*num+8)\n x[i].append(10*num+9)\n y[i] +=2\n else:\n x[i].append(10*num+(last-1))\n x[i].append(10*num+last)\n x[i].append(10*num+(last+1))\n y[i] +=3\n \n#print(y)\n#print(sum(y))\n\nz=[0,y[1]]\nfor i in range(2,11):\n z.append(z[-1]+y[i])\n#print(z)\n\nmaxi=0\nfor r in range(11):\n if z[r]<=K:\n maxi=max(maxi,r)\n \nketa=maxi+1\n\nprint(x[keta][K-y[maxi-1]])\n', 'K=int(input())\nx=[[0] for _ in range(11)]\ny=[ 0 for _ in range(11)]\n\nx[1]=[1,2,3,4,5,6,7,8,9]\ny[1]=9\n\nfor i in range(2,11):\n x[i].pop()\n for num in x[i-1]:\n last = num%10\n if last==0:\n x[i].append(10*num)\n x[i].append(10*num+1)\n y[i] +=2\n elif last==9:\n x[i].append(10*num+8)\n x[i].append(10*num+9)\n y[i] +=2\n else:\n x[i].append(10*num+(last-1))\n x[i].append(10*num+last)\n x[i].append(10*num+(last+1))\n y[i] +=3\n \n#print(y)\n#print(sum(y))\n\nz=[0,y[1]]\nfor i in range(2,11):\n z.append(z[-1]+y[i])\n#print(z)\n\nketa=0\nfor i,num in enumerate(z):\n if num<=K:\n keta=i+1\n\ns= K-z[keta-1]\n#print(s)\nprint(x[keta][s-1])']
['Runtime Error', 'Accepted']
['s570372919', 's579139708']
[12000.0, 12000.0]
[84.0, 84.0]
[700, 680]
p02720
u090972687
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\n\nk = int(input())\n\nque = deque([1,2,3,4,5,6,7,8,9])\n\nfor n in range(0, k):\n x = que.popleft()\n if x % 10 != 0:\n que.append(x * 10 + x % 10 - 1)\n q.append(c * 10 + c % 10)\n if x % 10 != 9:\n que.append(x * 10 + x % 10 + 1)\n\nprint(x)', 'from collections import deque\n\nk = int(input())\n\nque = deque([1,2,3,4,5,6,7,8,9])\n\nfor n in range(0, k):\n x = que.popleft()\n if x % 10 != 0:\n que.append(x * 10 + x % 10 - 1)\n que.append(x * 10 + x % 10)\n if x % 10 != 9:\n que.append(x * 10 + x % 10 + 1)\n\nprint(x)']
['Runtime Error', 'Accepted']
['s533445708', 's168151011']
[3316.0, 11908.0]
[21.0, 123.0]
[270, 272]
p02720
u091307273
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def main():\n k = int(input())\n hp = list(range(1, 10))\n for i in range(k-1):\n n = hp.pop(0)\n if n % 10 != 0:\n hp.append(n * 10 + n - 1)\n hp.append(n * 10 + n)\n if n % 10 != 9:\n hp.append(n * 10 + n + 1)\n print(hp[0])\n', 'def main():\n k = int(input())\n hp = [i for i in range(k+4)]\n r, w = 1, 10\n while w <= k:\n n = hp[r]\n r += 1\n nm = n % 10\n val = n * 10 + nm\n \n if nm != 0:\n hp[w] = val - 1\n w += 1\n hp[w] = val\n w += 1\n if nm != 9:\n hp[w] = val + 1\n w += 1\n\n print(hp[k])\n\nmain()\n']
['Wrong Answer', 'Accepted']
['s253804167', 's527845365']
[8868.0, 13972.0]
[27.0, 43.0]
[279, 384]
p02720
u095021077
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['\nfrom collections import deque\n\n\ndef f(x):\n s=str(x) \n y=int(s[-1]) \n return s+str(y-1) \n\n\ndef g(x):\n s=str(x) \n y=int(s[-1]) \n return s+str(y) \n\n\ndef h(x):\n s=str(x) \n y=int(s[-1]) \n return s+str(y+1) \n\n\nK=int(input())\n\n\nq=deque()\n\n\nfor i in range(1, 10):\n q.append(i)\n \n\n\nfor i in range(K-1):\n num=q.popleft()\u3000\n if v%10!=0: \n q.append(f(num))\n \n q.append(g(num))\n \n if v%10!=9: \n q.append(h(num))\n \nprint(q.popleft()) ', '\nfrom collections import deque\n\n\ndef f(x):\n s=str(x) \n y=int(s[-1]) \n return int(s+str(y-1)) \n\n\ndef g(x):\n s=str(x) \n y=int(s[-1]) \n return int(s+str(y)) \n\n\ndef h(x):\n s=str(x) \n y=int(s[-1]) \n return int(s+str(y+1)) \n\n\nK=int(input())\n\n\nq=deque()\n\n\nfor i in range(1, 10):\n q.append(i)\n \n\n\nfor i in range(K-1):\n num=q.popleft() \n if num%10!=0: \n q.append(f(num))\n \n q.append(g(num))\n \n if num%10!=9: \n q.append(h(num))\n \nprint(q.popleft()) ']
['Runtime Error', 'Accepted']
['s360365174', 's545939007']
[3060.0, 10876.0]
[17.0, 368.0]
[1690, 1707]
p02720
u096190786
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def main(argv):\n k = int(sys.stdin.readline().rstrip("\\n"))\n if k < 10:\n return print(k)\n d = {i: [i] for i in range(10)}\n\n counter = 9\n n = 1\n while counter < k:\n next_d = {}\n candidates = d[0]\n candidates.extend(d[1])\n next_d[0] = sorted([c for c in set(candidates)])\n for i in range(1, 10):\n candidates = d[i - 1]\n candidates.extend(d[i])\n candidates.extend(d.get(i + 1, []))\n next_d[i] = sorted([i * (10 ** n) + c for c in set(candidates)])\n n_candidates = len(next_d[i])\n if (counter + n_candidates) >= k:\n print(next_d[i][k - counter - 1])\n counter += n_candidates\n break\n counter += n_candidates\n d = next_d\n n += 1\n return 0\n\nif __name__ == "__main__":\n sys.exit(main(sys.argv))', 'import sys\n\ndef main(argv):\n k = int(sys.stdin.readline().rstrip("\\n"))\n if k < 10:\n return print(k)\n d = {i: [i] for i in range(10)}\n\n counter = 9\n n = 1\n while counter < k:\n next_d = {}\n candidates = d[0]\n candidates.extend(d[1])\n next_d[0] = sorted([c for c in set(candidates)])\n for i in range(1, 10):\n candidates = d[i - 1]\n candidates.extend(d[i])\n candidates.extend(d.get(i + 1, []))\n next_d[i] = sorted([i * (10 ** n) + c for c in set(candidates)])\n n_candidates = len(next_d[i])\n if (counter + n_candidates) >= k:\n print(next_d[i][k - counter - 1])\n counter += n_candidates\n break\n counter += n_candidates\n d = next_d\n n += 1\n return 0\n\n\nif __name__ == "__main__":\n sys.exit(main(sys.argv))\n']
['Runtime Error', 'Accepted']
['s385729613', 's914305761']
[3064.0, 8204.0]
[17.0, 80.0]
[888, 902]
p02720
u104935308
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def main():\n K = int(input())\n\n q = queue.Queue()\n for i in range(9):\n q.put(i+1)\n\n count = 0\n while True:\n count = count+1\n a = q.get()\n\n if count == K:\n break\n\n tail = int(str(a)[-1])\n for i in range(10):\n if abs(tail-i) > 1:\n continue\n q.put(int(str(a)+str(i)))\n\n print(a)', 'import queue\n\ndef main():\n K = int(input())\n\n q = queue.Queue()\n for i in range(9):\n q.put(i+1)\n\n count = 0\n while True:\n count = count+1\n a = q.get()\n\n if count == K:\n break\n\n tail = int(str(a)[-1])\n for i in range(10):\n if abs(tail-i) > 1:\n continue\n q.put(int(str(a)+str(i)))\n\n print(a)\n\nif __name__ == "__main__":\n main()']
['Wrong Answer', 'Accepted']
['s939674420', 's011967653']
[3064.0, 12768.0]
[17.0, 1457.0]
[383, 436]
p02720
u106181248
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\ni = 1 \nc = 0 \n\nif k > 13000:\n i = 34454557\n c = 13000\n\nwhile c < k:\n j = str(i)\n if i < 13: \n c = c + 1 \n #print(c, i)\n else: \n x = 0\n for n in range(len(j)-1): 判定を行う\n if abs(int(j[n]) - int(j[n+1])) > 1:\n x = 1\n break\n if x == 0:\n c = c + 1\n #print(c, i)\n i = i + 1 \n\nprint(i-1)', 'k = int(input())\nans = 0 \ni = 1 \nc = 0 \n\nwhile c < k:\n j = str(i)\n if i < 13: \n c = c + 1 \n print(c, i)\n else: \n x = 0\n for n in range(len(j)-1): 判定を行う\n if abs(int(j[n]) - int(j[n+1])) > 1:\n x = 1\n break\n if x == 0:\n c = c + 1\n print(c, i)\n i = i + 1 \n\nprint(i-1)', 'k = int(input())\nans = 0 \ni = 1 \nc = 0 \n\nwhile c < k:\n j = str(i)\n if i < 13: \n c = c + 1 \n #print(c, i)\n else: \n x = 0\n for n in range(len(j)-1): 判定を行う\n if abs(int(j[n]) - int(j[n+1])) > 1:\n x = 1\n break\n if x == 0:\n c = c + 1\n #print(c, i)\n i = i + 1 \n\nprint(i-1)', 'k = int(input())\nlunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] \n\nfor i in range(k):\n x = lunlun[i]\n if x%10 != 0:\n lunlun.append(x*10+x%10-1)\n lunlun.append(x*10+x%10)\n if x%10 != 9:\n lunlun.append(x*10+x%10+1)\n #print(lunlun)\nprint(x)']
['Time Limit Exceeded', 'Wrong Answer', 'Time Limit Exceeded', 'Accepted']
['s460226070', 's656660990', 's885359081', 's145412506']
[3064.0, 3316.0, 3064.0, 15784.0]
[2104.0, 2104.0, 2104.0, 125.0]
[520, 488, 490, 284]
p02720
u106778233
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k=int(input())\n\nfrom collections import deque\ng=deque((1,2,3,4,5,6,7,8,9))\n\nb=[[str(k) for k in range(10) if -2<=k-i<3] for i in range(10)]\n\nfor i in range(10,1000000):\n i1=list(str(i))\n e1=len(i1)\n for h in range(e1-1):\n if not i1[h+1] in b[int(i1[h])]:\n break\n else:g.append(i)\n\n\nprint(g[k-1])', 'from collections import deque \nk=int(input())\ndq=deque()\nfor i in range(1,10):\n dq.append(i)\n\ncnt=1\nwhile cnt<k:\n now=dq.popleft()\n if now%10>=1:\n dq.append(now*10+now%10-1)\n dq.append(now*10+now%10)\n if now%10<=8:\n dq.append(now*10+now%10+1)\n cnt+=1\nprint(dq.popleft())\n']
['Runtime Error', 'Accepted']
['s230619123', 's330103146']
[4280.0, 11908.0]
[2000.0, 137.0]
[307, 303]
p02720
u133745933
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['\nK = int(input())\nn = 0\ncnt = 0\ntmp = 0\nwhile cnt < K:\n n = n + 1\n print(n)\n nDigit = []\n nDiv = []\n flg = True\n digits = len(str(n))\n tmpN = n\n for i in range(0,digits) :\n nDigit.append(tmpN // (10 ** (digits-i-1)))\n tmpN = tmpN % (10 ** (digits-i-1))\n if len(nDigit) == 1 :\n cnt = cnt + 1\n tmp = n\n else :\n tR = 0\n for i in range(0,len(nDigit)-1) :\n if abs(nDigit[i] - nDigit[i+1]) > 1 :\n flg = False\n tR = i\n i = len(nDigit)\n if flg == True :\n cnt = cnt + 1\n tmp = n\n elif nDigit[tR] - nDigit[tR+1] < 0 :\n n = n - (n % (10 ** (digits - tR))) + (nDigit[tR] + 1) * (10 ** (digits-tR-1)) - 1\n elif nDigit[tR] - nDigit[tR+1] > 0 :\n n = n - (n % (10 ** (digits - tR-1))) + (nDigit[tR] - 1) * (10 ** (digits-tR-2)) - 1\n\n\n# print(i,LunList[i])\nprint(n)\n', 'k = int(input())\n\ni = 1\nq = []\nwhile i <= k :\n if(i < 10) :\n q.append(i)\n else :\n x = q.pop(0)\n tmp = 10 * x + (x % 10)\n if x % 10 != 0 :\n q.append(tmp-1)\n i+=1\n q.append(tmp)\n if x % 10 != 9 :\n q.append(tmp+1)\n i+=1\n i+=1\nprint(q.pop(k-i))\n']
['Wrong Answer', 'Accepted']
['s841201514', 's586569005']
[4996.0, 5880.0]
[2104.0, 392.0]
[980, 336]
p02720
u133936772
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k=int(input());l=list(range(1,10))\nfor i in l:\n if len(l)==k: print(i); break\n for j in range(max(i%10-1,0),min(i%10+2,10)): l+=[i*10+j]', 'k=int(input());l=list(range(1,10))\nfor i in l:\n for j in range(max(i%10-1,0),min(i%10+2,10)):l+=[i*10+j]\n if len(l)>k:break\nprint(l[k-1])']
['Wrong Answer', 'Accepted']
['s082623734', 's253298621']
[171416.0, 7320.0]
[2115.0, 76.0]
[138, 139]
p02720
u150788544
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["n,m = map(int,input().split())\nlst = list(map(int,input().split()))\ns = 0\ntotal = sum(lst)\nfor i in range(n):\n if lst[i] >= total/(4*m):\n s += 1\n \nif s >= m:\n print('Yes')\nelse:\n print('No')\n \n\n", "import sys\nk = int(input())\nlst = [[0]*10 for i in range(10)]\nfor i in range(10):\n lst[0][i] = 1\nl_sum = [9] \n\n\nfor i in range(1,10):\n s = 0\n for j in range(10):\n if j == 0:\n lst[i][j] = lst[i-1][j] + lst[i-1][j+1]\n elif j == 9:\n lst[i][j] = lst[i-1][j] + lst[i-1][j-1] \n else:\n lst[i][j] = lst[i-1][j-1] + lst[i-1][j] + lst[i-1][j+1] \n \n if j !=0:\n s += lst[i][j]\n l_sum.append(s+l_sum[-1])\n \n\n\ni = 0\nif k < l_sum[0]:\n print(k)\n sys.exit()\nelse:\n while True:\n if k < l_sum[i]:\n break\n i += 1\n k = k - l_sum[i-1]\n \n ans = []\n for j in reversed(range(0, i+1)):\n \n if j == i:\n p = 1\n while True:\n if k - lst[j][p] <= 0:\n ans.append(p)\n break\n else:\n k -= lst[j][p]\n p += 1\n \n else:\n if p == 0:\n if k <= lst[j][p]:\n ans.append(p)\n else:\n k -= lst[j][p]\n p += 1\n ans.append(p)\n \n elif p == 9:\n if k <= lst[j][p-1]:\n p = p-1\n ans.append(p)\n else:\n k -= lst[j][p-1]\n ans.append(p)\n \n else:\n if k <= lst[j][p-1]:\n p = p-1\n ans.append(p)\n else:\n k -= lst[j][p-1]\n if k <= lst[j][p]:\n ans.append(p)\n else:\n k -= lst[j][p]\n p = p+1\n ans.append(p)\n \nl_s = [str(q) for q in ans]\nprint(''.join(l_s))\n "]
['Runtime Error', 'Accepted']
['s243709798', 's907383449']
[9040.0, 9328.0]
[28.0, 35.0]
[210, 1532]
p02720
u152331265
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\nlunlun = list(range(1, 10))\n\nfor i in range(k - 1):\n a = lunlun[i]\n b = a * 10 + a % 10\n if a % 10 != 0:\n lunlun.append(b - 1)\n lunlun.append(b)\n if a % 10 != 9:\n lunlun.append(b + 1)\nprint(lunlun)\nprint(lunlun[k - 1])', 'k = int(input())\nli = [i + 1 for i in range(9)]\n\nc = 0\nwhile len(li) < k:\n if li[c] % 10 != 0:\n li.append(li[c] * 10 + li[c] % 10 - 1)\n li.append(li[c] * 10 + li[c] % 10)\n if li[c] % 10 != 9:\n li.append(li[c] * 10 + li[c] % 10 + 1)\n c += 1\nprint(li[k - 1])']
['Wrong Answer', 'Accepted']
['s687680068', 's691469963']
[25876.0, 7200.0]
[131.0, 69.0]
[264, 282]
p02720
u161712560
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["def dfs(inParam, digits, lunlunCount, lunlun):\n if len(inParam) != digits:\n if int(inParam[len(inParam)-1]) == 0:\n nextNumList = [0, 1]\n elif int(inParam[len(inParam)-1]) == 9:\n nextNumList = [8, 9]\n else:\n nextNum = int(inParam[len(inParam)-1])\n nextNumList = [nextNum-1, nextNum, nextNum+1]\n \n for item in nextNumList:\n print(inParam+str(item))\n myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)\n lunlunCount = myTupp[0]\n print(myTupp)\n if myTupp[2] == 'e':\n return myTupp\n \n return myTupp\n \n else:\n lunlunCount += 1\n state = 'c'\n\n if lunlunCount == lunlun:\n state = 'e'\n print(inParam)\n\n return (lunlunCount, inParam, state)\n\nK = int(input())\n\nmylunlun = 0\nmydigits = 1\nwhile mylunlun != K:\n for indx in range(1, 10):\n mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)\n if mylunlun == K:\n break\n \n if mylunlun == K:\n break\n\n mydigits += 1\n", "def dfs(inParam, digits, lunlunCount, lunlun):\n if len(inParam) != digits:\n if int(inParam[len(inParam)-1]) == 0:\n nextNumList = [0, 1]\n elif int(inParam[len(inParam)-1]) == 9:\n nextNumList = [8, 9]\n else:\n nextNum = int(inParam[len(inParam)-1])\n nextNumList = [nextNum-1, nextNum, nextNum+1]\n \n for item in nextNumList:\n myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)\n lunlunCount = myTupp[0]\n if myTupp[2] == 'e':\n return myTupp\n \n return myTupp\n \n else:\n lunlunCount += 1\n state = 'c'\n\n if lunlunCount == lunlun:\n state = 'e'\n print(inParam)\n\n return (lunlunCount, inParam, state)\n\nK = int(input())\n\nmylunlun = 0\nmydigits = 1\nwhile mylunlun != K:\n for indx in range(1, 10):\n mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)\n \n # break\n \n if mylunlun == K:\n break\n\n mydigits += 1\n", 'K = int(input())\n\nif K <= 9:\n print(K)\nelse:\n mylun = 9\n lunList = []\n\n for indx in range(1, 10):\n lunList.append(str(indx))\n\n while mylun < K:\n newLunList = []\n for lunItem in lunList:\n if lunItem[len(lunItem)-1] != "0":\n mylun += 1\n newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))\n if mylun == K:\n print(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))\n break\n \n mylun += 1\n newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1]) ))\n if mylun == K:\n print(lunItem + str( int(lunItem[len(lunItem)-1]) ))\n break\n\n if lunItem[len(lunItem)-1] != "9":\n mylun += 1\n newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))\n if mylun == K:\n print(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))\n break\n \n lunList = newLunList\n']
['Wrong Answer', 'Time Limit Exceeded', 'Accepted']
['s106124771', 's273055563', 's302309862']
[8428.0, 3064.0, 8568.0]
[521.0, 2104.0, 125.0]
[1135, 1076, 1070]
p02720
u169350228
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import queue\nk = int(input)\nq = queue.Queue()\n\nfor i in range(1,10):\n q.put(i)\n\nfor i in range(k):\n x = q.get()\n if not x%10 == 0:\n q.put(10*x+(x%10)-1)\n q.put(10*x+(x%10))\n if not x%10 == 9:\n q.put(10*x+(x%10)+1)\n\nprint(x)\n', 'import queue\nk = int(input())\nq = queue.Queue()\n\nfor i in range(1,10):\n q.put(i)\n\nfor i in range(k):\n x = q.get()\n if not x%10 == 0:\n q.put(10*x+(x%10)-1)\n q.put(10*x+(x%10))\n if not x%10 == 9:\n q.put(10*x+(x%10)+1)\n\nprint(x)\n']
['Runtime Error', 'Accepted']
['s536705248', 's603082540']
[3952.0, 12452.0]
[27.0, 1036.0]
[253, 255]
p02720
u178465329
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import queue\n\nn = int(input())\n\n\nq = queue.Queue()\n\nfor i in range(1,10):\n q.put(i)\n\nx = 0\nfor i in range(n):\n x = q.get()\n l = x % 10\n print(x,l)\n if l != 0:\n q.put(x*10 + l - 1)\n q.put(x*10 + l)\n if l != 9:\n q.put(x*10 + l + 1)\n \n#while not q.empty():\n# print (q.get())\n \nprint(x)\n', 'import queue\n\nn = int(input())\n\n\nq = queue.Queue()\n\nfor i in range(1,10):\n q.put(i)\n\nx = 0\nfor i in range(n):\n x = q.get()\n l = x % 10\n# print(x,l)\n if l != 0:\n q.put(x*10 + l - 1)\n q.put(x*10 + l)\n if l != 9:\n q.put(x*10 + l + 1)\n \n#while not q.empty():\n# print (q.get())\n \nprint(x)\n']
['Wrong Answer', 'Accepted']
['s623077244', 's818837577']
[14036.0, 12480.0]
[1264.0, 1043.0]
[331, 332]
p02720
u185405877
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['n=int(input())\nfrom collections import deque\nk=deque([])\nz=0\nfor i in range(1,10):\n k.append(i)\nwhile z<n:\n m=k.pop\n k.popleft\n if m%10!=0:\n k.append(10*m+(m%10)-1)\n k.append(10*m+(m%10))\n if m%10!=9:\n k.append(10*m+(m%10)+1)\nprint(m)\n ', '\nn=int(input())\nfrom collections import deque\nk=deque([])\nz=9\nm=0\nif n<10:\n print(n)\n exit()\nfor i in range(1,10):\n k.append(i)\nwhile z!=n:\n m=k.pop()\n k.popleft\n if m%10!=0:\n ans=10*m+(m%10)-1\n k.append(ans)\n z+=1\n if z==n:\n print(ans)\n exit()\n ans=10*m+(m%10) \n k.append(ans)\n z+=1\n if z==n:\n print(ans)\n exit()\n if m%10!=9:\n ans=10*m+(m%10)+1\n k.append(ans)\n z+=1\n if z==n:\n print(ans)\n exit()\n', 'n=int(input())\nfrom collections import deque\nk=deque([])\nz=0\nm=0\nfor i in range(1,10):\n k.append(i)\nwhile z<n:\n m=k.pop()\n k.popleft\n if m%10!=0:\n k.append(10*m+(m%10)-1)\n k.append(10*m+(m%10))\n if m%10!=9:\n k.append(10*m+(m%10)+1)\n z+=1\nprint(m)', 'n=int(input())\nfrom collections import deque\nk=deque([])\nz=9\nm=0\nif n<10:\n print(n)\n exit()\nfor i in range(1,10):\n k.append(i)\nwhile z!=n:\n m=k.popleft()\n if m%10!=0:\n ans=10*m+(m%10)-1\n k.append(ans)\n z+=1\n if z==n:\n print(ans)\n exit()\n ans=10*m+(m%10) \n k.append(ans)\n z+=1\n if z==n:\n print(ans)\n exit()\n if m%10!=9:\n ans=10*m+(m%10)+1\n k.append(ans)\n z+=1\n if z==n:\n print(ans)\n exit()\n']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s018902581', 's373498926', 's933441348', 's704913539']
[3316.0, 371288.0, 371928.0, 6088.0]
[21.0, 2126.0, 2127.0, 69.0]
[271, 547, 281, 536]
p02720
u199830845
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import sys\nfrom collections import deque\nsys.setrecursionlimit(10 ** 6) \nto_index = lambda x: int(x) - 1 \nprint_list_in_2D = lambda x: print(*x, sep="\\n") \n\n\ndef input_int():\n return int(input())\n\ndef map_int_input():\n return map(int, input())\n\nMII = map_int_input\n\ndef MII_split():\n return map(int, input().split())\n\ndef MII_to_index():\n return map(to_index, input())\n\ndef MII_split_to_index():\n return map(to_index, input().split())\n\n\ndef list_int_inputs():\n return list(map(int, input()))\n\nLII = list_int_inputs\n\ndef LII_split():\n return list(map(int, input().split()))\n\n\ndef LII_2D(rows_number):\n return [LII() for _ in range(rows_number)]\n\ndef LII_split_2D(rows_number):\n return [LII_split() for _ in range(rows_number)]\n\nK = input_int()\n\nif K < 10: \n print(K)\nelse: \n dq = deque([i for i in range(1, 10)])\n count = 0\n while True:\n x = dq.popleft()\n count += 1\n if count == K:\n print(x)\n return\n d = x % 10\n if d != 0:\n dq.append(10 * x + d - 1)\n dq.append(10 * x + d)\n if d != 9:\n dq.append(10 * x + d + 1)', 'import sys\nfrom collections import deque\nsys.setrecursionlimit(10 ** 6) \nto_index = lambda x: int(x) - 1 \nprint_list_in_2D = lambda x: print(*x, sep="\\n") \n\n\ndef input_int():\n return int(input())\n\ndef map_int_input():\n return map(int, input())\n\nMII = map_int_input\n\ndef MII_split():\n return map(int, input().split())\n\ndef MII_to_index():\n return map(to_index, input())\n\ndef MII_split_to_index():\n return map(to_index, input().split())\n\n\ndef list_int_inputs():\n return list(map(int, input()))\n\nLII = list_int_inputs\n\ndef LII_split():\n return list(map(int, input().split()))\n\n\ndef LII_2D(rows_number):\n return [LII() for _ in range(rows_number)]\n\ndef LII_split_2D(rows_number):\n return [LII_split() for _ in range(rows_number)]\n\nK = input_int()\n\nif K < 10: \n print(K)\nelse: \n dq = deque([i for i in range(1, 10)])\n count = 0\n while True:\n x = dq.popleft()\n count += 1\n if count == K:\n print(x)\n exit()\n d = x % 10\n if d != 0:\n dq.append(10 * x + d - 1)\n dq.append(10 * x + d)\n if d != 9:\n dq.append(10 * x + d + 1)']
['Runtime Error', 'Accepted']
['s357608935', 's758886099']
[3064.0, 11960.0]
[18.0, 118.0]
[1544, 1544]
p02720
u201387466
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import sys\ninput=sys.stdin.readline\nK = int(input())\nLEN = 3234566667\n#S = input()[:-1]\n#N,M = map(int,input().split())\n#S,T = map(str,input().split())\n#A = list(map(int,input().split()))\n#A = [int(input()) for _ in range(N)]\n#S = [input() for _ in range(N)]\n#A = [list(map(int,input().split())) for _ in range(N)]\ndef enqueue(Q,x,tail):\n Q[tail] = x \n if tail+1 == LEN: \n tail = 0\n else:\n tail += 1\n return tail\ndef dequeue(Q,head):\n x = Q[head]\n if head+1 == LEN:\n head = 0\n else:\n head += 1\n return x,head\nQ = [1,2,3,4,5,6,7,8,9]+[0]*(LEN-9)\nhead = 0\ntail = 9\n\ni = 0\nwhile i < K:\n x,head = dequeue(Q,head)\n if x % 10 == 0:\n tail = enqueue(Q,10*x,tail)\n tail = enqueue(Q,10*x+1,tail)\n elif x % 10 == 9:\n tail = enqueue(Q,10*x+8,tail)\n tail = enqueue(Q,10*x+9,tail)\n else:\n y = x%10\n tail = enqueue(Q,10*x+y-1,tail)\n tail = enqueue(Q,10*x+y,tail)\n tail = enqueue(Q,10*x+y+1,tail)\n i += 1\nprint(x)', 'import sys\ninput=sys.stdin.readline\nK = int(input())\nLEN = 32345666\n#S = input()[:-1]\n#N,M = map(int,input().split())\n#S,T = map(str,input().split())\n#A = list(map(int,input().split()))\n#A = [int(input()) for _ in range(N)]\n#S = [input() for _ in range(N)]\n#A = [list(map(int,input().split())) for _ in range(N)]\ndef enqueue(Q,x,tail):\n Q[tail] = x \n if tail+1 == LEN: \n tail = 0\n else:\n tail += 1\n return tail\ndef dequeue(Q,head):\n x = Q[head]\n if head+1 == LEN:\n head = 0\n else:\n head += 1\n return x,head\nQ = [1,2,3,4,5,6,7,8,9]+[0]*(LEN-9)\nhead = 0\ntail = 9\n\ni = 0\nwhile i < K:\n x,head = dequeue(Q,head)\n if x % 10 == 0:\n tail = enqueue(Q,10*x,tail)\n tail = enqueue(Q,10*x+1,tail)\n elif x % 10 == 9:\n tail = enqueue(Q,10*x+8,tail)\n tail = enqueue(Q,10*x+9,tail)\n else:\n y = x%10\n tail = enqueue(Q,10*x+y-1,tail)\n tail = enqueue(Q,10*x+y,tail)\n tail = enqueue(Q,10*x+y+1,tail)\n i += 1\nprint(x)']
['Runtime Error', 'Accepted']
['s100023362', 's595724635']
[3064.0, 508532.0]
[20.0, 867.0]
[1209, 1207]
p02720
u207235471
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\nk=int(input())\ndeq=deque([1,2,3,4,5,6,7,8,9])\nfor in in range(k):\n a=deq.popleft()\n if not a%10==0:\n deq.append(a*10+a%10-1)\n deq.append(a*10+a%10)\n if a%10==9:\n deq.append(a*10+a%10+1)\nprint(a)\n \n ', 'from collections import deque\nk=int(input())\ndeq=deque([1,2,3,4,5,6,7,8,9])\nfor i in range(k):\n a=deq.popleft()\n if not a%10==0:\n deq.append(a*10+a%10-1)\n deq.append(a*10+a%10)\n if a%10==9:\n deq.append(a*10+a%10+1)\nprint(a)\n \n \n', 'from collections import deque\nk=int(input())\ndeq=deque([1,2,3,4,5,6,7,8,9])\nfor in range(k):\n a=deq.popleft()\n if not a%10==0:\n deq.append(a*10+a%10-1)\n deq.append(a*10+a%10)\n if a%10==9:\n deq.append(a*10+a%10+1)\nprint(a)\n \n \n', 'from collections import deque\nK=int(input())\nque=deque([1,2,3,4,5,6,7,8,9])\nfor i in range(K):\n a=que.popleft()\n if not a%10==0:\n que.append(a*10+a%10-1)\n que.append(a*10+a%10)\n if not a%10==9:\n que.append(a*10+a%10+1)\nprint(a)\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s073757114', 's185071064', 's936583369', 's401832876']
[2940.0, 6456.0, 2940.0, 11908.0]
[17.0, 93.0, 18.0, 127.0]
[242, 258, 241, 254]
p02720
u215286521
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['x = int(input())\n\np = []\nfor i in range(1, 10):\n p.append(i)\n\nans = 0\nindex = x\n\nwhile 1:\n if index <= len(p):\n break\n index -= len(p)\n for i in p:\n for j in range(-1, 2):\n d = i % 10 + j\n if d < 0 or d > 9:\n continue\n\n nx = i * 10 + d\n p.append(nx)\n\nans = p[x - 1]\nprint(ans)\n\n', 'x = int(input())\n\np = [None for _ in range(100)]\n\np[1] = (1,2,3,4,5,6,7,8,9)\n\ndef getByKeta(n):\n for i in p[n-1]:\n for j in range(-1, 2):\n d = i % 10 + j\n if d < 0 or d > 9:\n continue\n\n yield i * 10 + d\n\nfor i in range(2, 11):\n p[i] = tuple(getByKeta(i))\n\nans = 0\nfor i in range(1, 11):\n if x <= len(p[i]):\n ans = p[i][x-1]\n break\n x -= len(p[i])\nprint(ans)\n\n# p = []\n\n# p.append(i)\n\n# ans = 0\n# index = x\n\n# while 1:\n# if index <= len(p):\n# break\n# index -= len(p)\n\n# for j in range(-1, 2):\n\n# if d < 0 or d > 9:\n# continue\n\n\n# p.append(nx)\n\n# print(p)\n# print(len(p))\n# ans = p[1]\n# print(ans)\n\n']
['Time Limit Exceeded', 'Accepted']
['s384822403', 's853254286']
[190744.0, 12104.0]
[2116.0, 90.0]
[347, 820]
p02720
u218838821
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\n\ncount = 0\n\nfor i in range(1,10**10):\n l = len(str(i))\n if l == 1:\n count +=1\n ans = i\n if count == k:\n print(ans)\n break\n else:\n continue\n else:\n for j in range(l-1):\n if not abs(int(str(i)[j]) - int(str(i)[j+1])) <= 1:\n continue\n elif j ==l-1:\n count +=1\n ans = i\n if count == k:\n print(ans)\n break', 'import queue\nk = int(input())\n\nq = queue.Queue()\nfor i in range(1,10):\n q.put(i)\n\nfor i in range(k):\n x = q.get()\n if i == k-1:\n break\n else:\n if not x % 10 == 0:\n q.put(10*x + (x % 10) -1)\n q.put(10*x + (x % 10))\n if not x % 10 == 9:\n q.put(10*x + (x % 10) +1)\n\nprint(x)']
['Time Limit Exceeded', 'Accepted']
['s509425948', 's507739302']
[3064.0, 12452.0]
[2104.0, 1048.0]
[478, 333]
p02720
u223663729
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["import sys\nfrom itertools import accumulate\nK = int(input())\n\nMAX = 22\ndp = [[0]*10 for _ in [0]*MAX]\n\nfor j in range(0, 10):\n dp[1][j] = 1\n\nfor i in range(2, MAX):\n for j in range(1, 9):\n dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]\n dp[i][0] = dp[i-1][0] + dp[i-1][1]\n dp[i][9] = dp[i-1][8] + dp[i-1][9]\n\nacc = [[] for _ in [0]*MAX]\nfor i in range(1, MAX):\n acc[i] = accumulate(dp[i])\n\n\nnum = [0]\nfor i in range(1, MAX):\n num.append(num[i-1] + sum(dp[i][1:]))\n\nprint(dp[:6])\nprint(num)\n\ncnt = 0\nfor i, n in enumerate(num):\n if n < K:\n keta = i+1\n cnt = n\n else:\n break\n\nprint(keta, cnt)\nans = 0\n\nrg = range(1, 10)\np = 1\nfor i in range(keta, 0, -1):\n for j in rg:\n print('keta', i, 'suuji', j, 'cnt', cnt, 'dp', dp[i][j], 'ans', ans)\n if cnt + dp[i][j] < K:\n flg = True\n p = j+1\n cnt += dp[i][j]\n else:\n break\n\n ans += 10**(i-1)*p\n\n rg = range(max(0, p-1), min(10, p+2))\n p = p-1\n\nprint(ans)\n", 'from collections import deque\n\nK = int(input())\n\nq = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])\n\ncnt = 0\n\n\nwhile q:\n x = q.popleft()\n\n cnt += 1\n if cnt == K:\n print(x)\n break\n\n y = x % 10\n z = 10*x+y\n if y != 0:\n q.append(z-1)\n q.append(z)\n if y != 9:\n q.append(z+1)\n\n \n\n']
['Wrong Answer', 'Accepted']
['s661457115', 's988782833']
[3188.0, 11884.0]
[18.0, 109.0]
[1085, 327]
p02720
u228303592
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\ncand = [[1,2,3,4,5,6,7,8,9]]\nfor i in range(9):\n tmp = []\n for val in cand[-1]:\n if val % 10 != 0:\n tmp.append(val*10 + (val%10 - 1))\n tmp.append(val*10 + (val % 10))\n if val % 10 != 9:\n tmp.append(val*10 + (val%10 + 1))\n cand.append(tmp)\n\nans = []\nfor j in range(len(cand)):\n for val in cand[i]:\n ans.append(val)\nans = sorted(ans)\n\nprint(ans[k - 1])\n', 'k = int(input())\ncand = [[1,2,3,4,5,6,7,8,9]]\nfor i in range(9):\n tmp = []\n for val in cand[-1]:\n if val % 10 != 0:\n tmp.append(val*10 + (val%10 - 1))\n tmp.append(val*10 + (val % 10))\n if val % 10 != 9:\n tmp.append(val*10 + (val%10 + 1))\n cand.append(tmp)\n\nans = []\nfor j in range(len(cand)):\n for val in cand[i]:\n ans.append(val)\nans = sorted(ans)\n\nprint(ans[k - 1])', 'k = int(input())\ncand = [[1,2,3,4,5,6,7,8,9]]\nfor i in range(9):\n tmp = []\n for val in cand[-1]:\n if val % 10 != 0:\n tmp.append(val*10 + (val%10 - 1))\n tmp.append(val*10 + (val % 10))\n if val % 10 != 9:\n tmp.append(val*10 + (val%10 + 1))\n cand.append(tmp)\n\nans = []\nfor j in range(len(cand)):\n for val in cand[j]:\n ans.append(val)\nans = sorted(ans)\n\nprint(ans[k - 1])\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s546431013', 's747992050', 's014467789']
[27384.0, 54420.0, 22116.0]
[116.0, 324.0, 88.0]
[394, 395, 394]
p02720
u232903302
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import itertools\ndigits1 = [str(i) for i in range(1,10)]\ndigits2 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits1]))\ndigits3 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits2]))\ndigits4 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits3]))\ndigits5 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits4]))\ndigits6 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits5]))\ndigits7 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits6]))\ndigits8 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits7]))\ndigits9 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits8]))\ndigits10 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits9]))\nindex = digits1 + digits2 + digits3 + digits4 + digits5 + digits6 + digits7 + digits8 + digits9 + digits10\nK = int(input())\nprint(index[K-1])', 'import itertools\ndef addLunLun(str_num):\n last_digit = int(str_num[len(str_num)-1:])\n if last_digit == 0:\n return [str_num+"0",str_num+"1"]\n elif last_digit == 9:\n return [str_num+"8",str_num+"9"]\n else:\n return [str_num + str(last_digit-1),str_num + str(last_digit),str_num + str(last_digit+1)]\n \ndigits1 = [str(i) for i in range(1,10)]\ndigits2 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits1]))\ndigits3 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits2]))\ndigits4 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits3]))\ndigits5 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits4]))\ndigits6 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits5]))\ndigits7 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits6]))\ndigits8 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits7]))\ndigits9 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits8]))\ndigits10 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits9]))\nindex = digits1 + digits2 + digits3 + digits4 + digits5 + digits6 + digits7 + digits8 + digits9 + digits10\nK = int(input())\nprint(index[K-1])']
['Runtime Error', 'Accepted']
['s233896526', 's299641413']
[3064.0, 23140.0]
[17.0, 137.0]
[910, 1227]
p02720
u235210692
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['que = queue.Queue()\n\nfor i in range(1, 10):\n que.put(i)\n\nfor i in range(1, k + 1):\n ans = que.get()\n keta1 = ans % 10\n if keta1 == 0:\n append_list = [ans * 10, ans * 10 + 1]\n elif keta1 == 9:\n append_list = [ans * 10 + 8, ans * 10 + 9]\n else:\n append_list = [ans * 10 + keta1 - 1, ans * 10 + keta1, ans * 10 + keta1 + 1]\n for item in append_list:\n que.put(item)\nprint(ans)', 'import queue', 'k = int(input())\n\nimport queue\n\nque = queue.Queue()\n\nfor i in range(1, 10):\n que.put(i)\n\nfor i in range(1, k + 1):\n ans = que.get()\n keta1 = ans % 10\n if keta1 == 0:\n append_list = [ans * 10, ans * 10 + 1]\n elif keta1 == 9:\n append_list = [ans * 10 + 8, ans * 10 + 9]\n else:\n append_list = [ans * 10 + keta1 - 1, ans * 10 + keta1, ans * 10 + keta1 + 1]\n for item in append_list:\n que.put(item)\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s924459987', 's971795851', 's702589144']
[9040.0, 9572.0, 18680.0]
[25.0, 34.0, 581.0]
[421, 12, 453]
p02720
u242196904
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\nk = int(input())\nd = deque()\nd += [1,2,3,4,5,6,7,8,9]\nfor i in range(k):\n# print(d, now)\n now = d.popleft()\n if now%10 != 0:\n d.append(10 * now + now % 10 - 1)\n d.append(10 * now + now % 10)\n if now%10 != 9:\n d.append(10 * now + now % 10 + 1)\nprint(k, now)', 'from collections import deque\nk = int(input())\nd = deque()\nd += [1,2,3,4,5,6,7,8,9]\nfor i in range(k):\n# print(d, now)\n now = d.popleft()\n if now%10 != 0:\n d.append(10 * now + now % 10 - 1)\n d.append(10 * now + now % 10)\n if now%10 != 9:\n d.append(10 * now + now % 10 + 1)\nprint(now)']
['Wrong Answer', 'Accepted']
['s815430926', 's893304287']
[11908.0, 11908.0]
[119.0, 122.0]
[316, 313]
p02720
u250554058
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['n = int(input())\n\n\n', 'k = int(input())\nn = []\n\ndef dfs(num, A):\n A.append(num)\n\n if(len(str(num)) == 10):\n return 0\n\n for i in range(-1, 2):\n s = num%10 + i\n if(s >= 0 and s <= 9):\n dfs(num * 10 + s, A)\n\n return 0\n\nfor i in range(1, 10):\n dfs(i, n)\n\nn = sorted(n)\n\nprint(n[k - 1])\n']
['Wrong Answer', 'Accepted']
['s382687847', 's676915014']
[9200.0, 20820.0]
[23.0, 143.0]
[19, 278]
p02720
u265154666
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["# -*- coding: utf-8 -*-\n\n'''\n100000\n99990\n90000\n'''\n\nK = int(input())\n# K = 100000 - K\n\n# c = list(str(3234566667))\n\nc = 1\n\nfor i in range(K):\n str_c = list(str(c))\n str_c = [int(i) for i in str_c][::-1]\n\n keta = len(str_c)\n # print(c)\n # print(str_c)\n\n if set(str_c) == set([9]):\n c = c + 1\n continue\n\n for ket in range(keta):\n \n if ket == keta - 1:\n str_c[ket] += 1\n\n for j in range(ket):\n # print(str_c)\n if str_c[ket - j] == 0:\n str_c[ket - j - 1] = 0\n else:\n str_c[ket - j - 1] = str_c[ket - j] - 1\n\n str_c = [str(i) for i in str_c][::-1]\n c = int(''.join(str_c))\n break\n\n if str_c[ket] == str_c[ket + 1] + 1:\n continue\n\n \n if abs(str_c[ket] - str_c[ket + 1]) <= 1:\n if str_c[ket] < 9:\n str_c[ket] += 1\n for j in range(ket):\n if str_c[ket - j] == 0:\n str_c[ket - j - 1] = 0\n else:\n str_c[ket - j - 1] = str_c[ket - j] - 1\n str_c = [str(i) for i in str_c][::-1]\n c = int(''.join(str_c))\n break\n\n\nprint(c)\n\n", "# -*- coding: utf-8 -*-\n\n'''\n100000\n99990\n90000\n'''\n\nK = int(input())\nK = 100000 - K\nc = list(str(3234566667))\nc = [int(i) for i in c][::-1]\n\nfor i in range(K):\n keta = len(c)\n # print(c)\n\n for ket in range(keta):\n if ket == keta - 1:\n if c[ket] > 1:\n c[ket] = c[ket] - 1\n for j2 in range(ket - 1):\n c[ket - j2 - 1] = c[ket - j2 - 1] + 1\n break\n else:\n for j2 in range(ket - 1):\n c[ket - j2 - 1] = 9\n c = c[:-1]\n break\n\n if c[ket] == 0:\n continue\n\n if c[ket] >= c[ket + 1]:\n c[ket] = c[ket] - 1\n\n for j in range(ket):\n if c[ket] == 9:\n c[ket - j - 1] = 9\n elif c[ket] == 0 and c[ket + 1] == 0:\n c[ket - j - 1] = 0\n else:\n if c[ket - j] == 9:\n c[ket - j - 1] = 9\n else:\n c[ket - j - 1] = c[ket - j] + 1\n break\n\n\n[print(int(i), end='') for i in c[::-1]]\nprint('')\n", "# -*- coding: utf-8 -*-\n\n'''\n100000\n99990\n90000\n'''\n\nK = int(input())\n# K = 100000 - K\n\n# c = list(str(3234566667))\n\nc = 1\n\nfor i in range(K -1):\n str_c = list(str(c))\n str_c = [int(i) for i in str_c][::-1]\n\n keta = len(str_c)\n # print(c)\n # print(str_c)\n\n if set(str_c) == set([9]):\n c = c + 1\n continue\n\n for ket in range(keta):\n \n if ket == keta - 1:\n str_c[ket] += 1\n\n for j in range(ket):\n # print(str_c)\n if str_c[ket - j] == 0:\n str_c[ket - j - 1] = 0\n else:\n str_c[ket - j - 1] = str_c[ket - j] - 1\n\n str_c = [str(i) for i in str_c][::-1]\n c = int(''.join(str_c))\n break\n\n if str_c[ket] == str_c[ket + 1] + 1:\n continue\n\n \n if abs(str_c[ket] - str_c[ket + 1]) <= 1:\n if str_c[ket] < 9:\n str_c[ket] += 1\n for j in range(ket):\n if str_c[ket - j] == 0:\n str_c[ket - j - 1] = 0\n else:\n str_c[ket - j - 1] = str_c[ket - j] - 1\n str_c = [str(i) for i in str_c][::-1]\n c = int(''.join(str_c))\n break\n\n\nprint(c)\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s491311365', 's753864872', 's639915415']
[3064.0, 3064.0, 3064.0]
[875.0, 129.0, 909.0]
[1400, 1153, 1402]
p02720
u266014018
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\nstack = list(range(1,10))\nfor i in range(k):\n num = stack.pop(0)\n if (m:=num%10) == 0:\n stack.append([num*10 + m,num*10+m+1])\n elif m == 9:\n stack.append([num*1 + m -1,num*10 + m])\n else:\n stack.append([num*10 + m -1,num*10 + m, num*10+ m + 1])\nprint(num)', "def main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n k = int(input())\n from collections import deque\n que = deque(range(1, 10))\n for i in range(k):\n now = que.popleft()\n r = now%10\n nx = now*10\n if r == 0:\n for j in [0, 1]:\n que.append(nx+r+j)\n elif r == 9:\n for j in [-1, 0]:\n que.append(nx+r+j)\n else:\n for j in [-1, 0, 1]:\n que.append(nx+r+j)\n print(now)\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s484463830', 's893124651']
[9196.0, 18952.0]
[25.0, 82.0]
[285, 560]
p02720
u267466261
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import queue\n\nk = int(input())\nq = queue.Queue()\nfor i in range(1,9):\n q.put(i)\n\nn = 0\nwhile True:\n val = q.get()\n if val % 10 != 0:\n q.put(10 * val + (val % 10) - 1)\n q.put(10 * val + (val % 10))\n if val % 10 != 9:\n q.put(10 * val + (val % 10) + 1)\n \n n += 1\n if n == k:\n print(val)\n break', 'import queue\n\nk = int(input())\nq = queue.Queue()\nfor i in range(1,9):\n q.put(i)\n\nn = 0\nwhile True:\n val = q.get()\n if val % 10 != 0:\n q.put(10 * val + (val % 10) - 1)\n q.put(10 * val + (val % 10))\n if val % 10 != 9:\n q.put(10 * val + (val % 10) + 1)\n \n n += 1\n if n == k:\n print(val)\n break', 'mport queue\n\nk = int(input())\nq = queue.Queue()\nfor i in range(1,9):\n q.put(i)\n\nn = 0\nwhile True:\n val = q.get()\n if val % 10 != 0:\n q.put(10 * val + (val % 10) - 1)\n q.put(10 * val + (val % 10))\n if val % 10 != 9:\n q.put(10 * val + (val % 10) + 1)\n \n n += 1\n if n == k:\n print(val)\n break', 'import queue\n\nk = int(input())\nq = queue.Queue()\nfor i in range(1,10):\n q.put(i)\n\nn = 0\nwhile True:\n val = q.get()\n n += 1\n if n == k:\n print(val)\n break\n\n if val % 10 != 0:\n q.put(10 * val + (val % 10) - 1)\n q.put(10 * val + (val % 10))\n if val % 10 != 9:\n q.put(10 * val + (val % 10) + 1)\n \n ']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s375761349', 's525315077', 's785620541', 's393708182']
[12544.0, 12544.0, 2940.0, 12452.0]
[1052.0, 1060.0, 17.0, 1088.0]
[310, 310, 309, 315]
p02720
u290886932
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def Add_(N):\n M = N\n C = 1\n while M > 10:\n M = M // 10\n C += 1\n if M == 1:\n return [ M * 10**C + N,(M+1) * 10**C + N ]\n elif M == 9:\n return [ (M-1) * 10**C + N, M * 10**C + N ]\n else:\n return [(M-1) * 10**C + N, M * 10**C + N,(M+1) * 10**C + N ]\n\nX = int(input())\nR = [1,2,3,4,5,6,7,8,9]\nR_list = [[0]]\nR_list.append(R)\nn = 9\nd = 1\nwhile n < X:\n list1 = R_list[-2] \n list1 = list(map(lambda x: x + 10**d, list1) )\n list_ = [10 ** d]\n list_.extend(list1)\n for i in R_list[-1]:\n temp = Add_(i)\n list_.extend(temp)\n n += len(temp)\n d += 1\n R_list.append(list_)\n\nR = list()\nfor list_ in R_list:\n R.extend(list_)\nR.sort()\nprint(R[X])', 'def add(N):\n n = N % 10\n ret = N * 10\n if n == 0:\n return [ret, ret + 1]\n elif n == 9:\n return [ret + 9,ret + 8]\n else:\n return [ret + n - 1, ret + n, ret + n + 1]\n\nX = int(input())\nl = [1,2,3,4,5,6,7,8,9]\nlists = list()\nlists.append(l)\nn = 9\nwhile n < X:\n list_ = lists[-1]\n templist = list()\n for l_ in list_:\n vals = add(l_)\n n += len(vals)\n templist.extend(vals)\n lists.append(templist)\n\nR = list()\nfor list_ in lists:\n R.extend(list_)\nR.sort()\nprint(R[X-1]) ']
['Wrong Answer', 'Accepted']
['s684771562', 's282671994']
[9000.0, 13280.0]
[129.0, 81.0]
[727, 535]
p02720
u296557772
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\ndef main(k):\n q = deque([])\n for i in range(10):\n q.append(i)\n \n count = 0\n top = -1\n while True:\n top = q.popleft()\n\n count += 1\n if count == k:\n return top\n\n if top%10 != 0:\n q.append(top*10 + top%10-1)\n q.append(top*10 + top%10)\n if top%10 != 9:\n q.append(top*10 + top%10 + 1)\n\n return top\n\nk = int(input())\nmain(k)', 'from collections import deque\ndef main(k):\n q = deque([])\n for i in range(1, 10):\n q.append(i)\n \n count = 0\n top = -1\n \n while True:\n top = q.popleft()\n\n count += 1\n if count == k:\n return top\n\n if top%10 != 0:\n q.append(top*10 + top%10-1)\n q.append(top*10 + top%10)\n if top%10 != 9:\n q.append(top*10 + top%10 + 1)\n\n return top\n\nmain(k)', 'from collections import deque\ndef main(k):\n q = deque([])\n for i in range(1, 10):\n q.append(i)\n \n count = 0\n top = -1\n \n while True:\n top = q.popleft()\n\n count += 1\n if count == k:\n return top\n\n if top%10 != 0:\n q.append(top*10 + top%10-1)\n q.append(top*10 + top%10)\n if top%10 != 9:\n q.append(top*10 + top%10 + 1)\n\n return top\nk = int(input())\nmain(k)', 'from collections import deque\ndef main(k):\n q = deque([])\n for i in range(1, 10):\n q.append(i)\n \n count = 0\n top = -1\n \n while True:\n top = q.popleft()\n \n count += 1\n if count == k:\n return top\n \n if top%10 != 0:\n q.append(top*10 + top%10-1)\n q.append(top*10 + top%10)\n if top%10 != 9:\n q.append(top*10 + top%10 + 1)\n \n return top\nk = int(input())\nprint(main(k))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s041573355', 's111689294', 's637364500', 's655304566']
[11868.0, 3316.0, 11904.0, 11904.0]
[112.0, 22.0, 115.0, 114.0]
[451, 442, 458, 468]
p02720
u306950978
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\ncou = 0\nwhile True:\n cou += 1\n t = q.get()\n if cou == k:\n print(t)\n exit()\n if t % 10 == 0:\n q.put(t*10)\n q.put(t*10 + 1)\n elif t % 10 == 9:\n q.put(t*10 + 8)\n q.put(t*10 + 9)\n else:\n s = t % 10\n q.put(t*10 + s -1)\n q.put(t*10 + s)', 'import queue\n\nq = queue.Queue()\nfor i in range(1,10):\n q.put(i)\n\nk = int(input())\ncou = 0\nwhile True:\n cou += 1\n t = q.get()\n if cou == k:\n print(t)\n exit()\n if t % 10 == 0:\n q.put(t*10)\n q.put(t*10 + 1)\n elif t % 10 == 9:\n q.put(t*10 + 8)\n q.put(t*10 + 9)\n else:\n s = t % 10\n q.put(t*10 + s -1)\n q.put(t*10 + s)\n q.put(t*10 + s + 1)']
['Runtime Error', 'Accepted']
['s964271188', 's771033283']
[3064.0, 12576.0]
[17.0, 1056.0]
[328, 424]
p02720
u311488536
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\nK = int(input())\nqueue = deque([1,2,3,4,5,6,7,8,9])\ncount = 1\nwhile count <= K:\n num = queue.popleft()\n if num%10!=0:\n queue.append(num*10+num%10-1)\n queue.append(num*10+num%10)\n if num%!=9:\n queue.append(num*10+num%10+1)\n \nprint(num)', 'from collections import deque\nK = int(input())\nqueue = deque([1,2,3,4,5,6,7,8,9])\ncount = 1\nwhile count <= K:\n num = queue.popleft()\n if num%10!=0:\n queue.append(num*10+num%10-1)\n queue.append(num*10+num%10)\n if num%10!=9:\n queue.append(num*10+num%10+1)\n count+=1\n \nprint(num)']
['Runtime Error', 'Accepted']
['s387024926', 's946438591']
[9040.0, 18832.0]
[23.0, 110.0]
[275, 288]
p02720
u314089899
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['#161d\nimport math\nimport copy\n\nK = int(input())\n\nketa = 1\nlunlun_numbers_list = [1,2,3,4,5,6,7,8,9]\nlunlun_numbers_numer = 9\n\nif K <=9:\n print(lunlun_numbers_list[K-1])\nelse:\n while 1:\n new_lunlun_numbers_list = list()\n for lower_keta in lunlun_numbers_list:\n ketasu = int(math.log10(lower_keta)//1 + 1)\n top_keta = lower_keta // 10**(ketasu-1)\n\n if top_keta !=1: \n \n new_lunlun_numbers_list.append((top_keta-1)*10**ketasu + lower_keta)\n\n \n new_lunlun_numbers_list.append((top_keta+0)*10**ketasu + lower_keta)\n\n if top_keta !=9:\n \n new_lunlun_numbers_list.append((top_keta+1)*10**ketasu + lower_keta)\n\n \n ketasu = int(math.log10(new_lunlun_numbers_list[-1])//1 + 1)\n new_lunlun_numbers_list.append((1)*10**(ketasu-1))\n \n if ketasu !=2: \n new_lunlun_numbers_list.append((1)*10**(ketasu-1)+1)\n\n\n if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:\n new_lunlun_numbers_list.sort(reverse=False)\n print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])\n print(new_lunlun_numbers_list)\n break\n\n\n lunlun_numbers_list = copy.copy(new_lunlun_numbers_list) \n', 'K = int(input())\n\ndef get_next_lun(before_number,keta): \n\n if keta == 1: \n if before_number == 9:\n return [8,9]\n if before_number == 0:\n return [1,2]\n else:\n return [before_number-1,before_number,before_number+1]\n else:\n if before_number == 9:\n for i in get_next_lun(before_number,keta-1):\n return []\n if before_number == 0:\n return []\n else:\n return [before_number-1,before_number,before_number+1]\n \n return \n', '#161d\nimport math\nimport copy\n\nK = int(input())\n\nketa = 1\nlunlun_numbers_list = [1,2,3,4,5,6,7,8,9]\nlunlun_numbers_numer = 9\n\nif K <=9:\n print(lunlun_numbers_list[K-1])\nelse:\n while 1:\n new_lunlun_numbers_list = list()\n for lower_keta in lunlun_numbers_list:\n ketasu = int(math.log10(lower_keta)//1 + 1)\n\n if lower_keta>=10:\n last_keta = lower_keta - ((lower_keta//10) * 10)\n else:\n last_keta = lower_keta\n\n #print(lower_keta,ketasu,last_keta)\n\n if last_keta !=0: \n new_lunlun_numbers_list.append(lower_keta*10 + last_keta - 1)\n \n new_lunlun_numbers_list.append(lower_keta*10 + last_keta)\n\n if last_keta !=9:\n new_lunlun_numbers_list.append(lower_keta*10 + last_keta + 1)\n\n if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:\n new_lunlun_numbers_list.sort(reverse=False)\n print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])\n #print(new_lunlun_numbers_list)\n break\n else:\n lunlun_numbers_numer+=len(new_lunlun_numbers_list)\n\n lunlun_numbers_list = copy.copy(new_lunlun_numbers_list) ']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s279259793', 's374351850', 's287140195']
[16188.0, 2940.0, 11692.0]
[251.0, 17.0, 141.0]
[1498, 530, 1238]
p02720
u332933608
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def d1(x):\n y = x % 10\n if y == 0:\n return [0, 1]\n elif y == 9:\n return [8, 9]\n else:\n return [y-1, y, y+1]\n\n\nK = int(input())\n\nrunrun = []\nN = 0\ndigit = 0\nwhile N < K:\n d_i = []\n if digit == 0:\n for i in range(1, 10):\n d_i.append(i)\n N += len(d_i)\n runrun.append(d_i)\n digit += 1\n else:\n tmp = runrun[digit-1]\n for x in tmp:\n for y in d1(x):\n d_i.append(10*x+y)\n N += len(d_i)\n runrun.append(d_i)\n digit += 1\n\nprint(runrun[-1][K-N+1])', 'def d1(x):\n y = x % 10\n if y == 0:\n return [0, 1]\n elif y == 9:\n return [8, 9]\n else:\n return [y-1, y, y+1]\n\n\nK = int(input())\n\nrunrun = []\nN = 0\ndigit = 0\nwhile N < K:\n d_i = []\n if digit == 0:\n for i in range(1, 10):\n d_i.append(i)\n N += len(d_i)\n runrun.append(d_i)\n digit += 1\n else:\n tmp = runrun[digit-1]\n for x in tmp:\n for y in d1(x):\n d_i.append(10*x+y)\n N += len(d_i)\n runrun.append(d_i)\n digit += 1\n\nprint(runrun[-1][K-N-1])\n']
['Wrong Answer', 'Accepted']
['s971611421', 's089662566']
[11996.0, 11996.0]
[85.0, 87.0]
[577, 578]
p02720
u336564899
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\ntime = 1\n\ndp0 = [1]#0,9\ndp1 = [8]#1~8\np = [9]\n\nfor i in range(100):\n dp0.append(dp0[i]*2 + 2)\n dp1.append(dp1[i]*3 - 2)\n p.append(dp0[i+1] + dp1[i+1] + p[i])\n\n if p[len(p)-1] > k:\n break\n\n#print(len(p))\ns = k - p[len(p)-2]\nw = [0]*len(p)\nprint(s,w)\n', 'import collections\n\nk = int(input())\ntime = 1\n\nq = collections.deque()\n\nq.extend([1,2,3,4,5,6,7,8,9])\n\nwhile(time <= k):\n\n i = q.popleft()\n #print(i)\n time += 1\n\n \n if i % 10 != 0:\n q.append(i*10 + i%10 - 1)\n\n \n q.append(i*10 + i%10)\n\n \n if i % 10 != 9:\n q.append(i*10 + i%10 + 1)\n\nprint(i)\n']
['Wrong Answer', 'Accepted']
['s532212290', 's105023131']
[3064.0, 11872.0]
[17.0, 140.0]
[285, 385]
p02720
u349724238
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["K = int(input())\nA = [1,2,3,4,5,6,7,8,9,10]\nfor i in range(len(A)):\n if A[i] % 10 == 0:\n A.append(100)\n A.append(101)\n elif A[i] != 9:\n for j in range(-1,2):\n a = int(str(A[i]) + str(A[i]+j))\n A.append(a)\n else:\n A.append(98)\n A.append(99)\nL1 = len(A.copy())\nfor i in range(10,L1):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nL2 = len(A.copy())\nfor i in range(L1,L2):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B%10) + j))\n A.append(a)\nL3 = len(A.copy())\nfor i in range(L2,L3):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nL4 = len(A.copy())\nfor i in range(L3,L4):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nL5 = len(A.copy())\nfor i in range(L4,L5):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nL6 = len(A.copy())\nfor i in range(L5,L6):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nL7 = len(A.copy())\nfor i in range(L6,L7):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nL8 = len(A.copy())\nfor i in range(L7,L8):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\nA = sorted(A)\n# print(A)\nprint(A[K-1])\n\n", "K = int(input())\nA = [1,2,3,4,5,6,7,8,9]\nfor i in range(len(A)):\n if A[i] != 9:\n for j in range(-1,2):\n a = int(str(A[i]) + str(A[i]+j))\n A.append(a)\n else:\n A.append(98)\n A.append(99)\nA.append(100)\nA.append(101)\nL1 = 10\nL2 = len(A.copy())\nfor i in range(8):\n for i in range(L1,L2):\n B = A[i]\n if B % 10 == 0:\n A.append(int(str(B) + '0'))\n A.append(int(str(B) + '1'))\n elif B % 10 == 9:\n A.append(int(str(B) + '8'))\n A.append(int(str(B) + '9'))\n else:\n for j in range(-1, 2):\n a = int(str(B) + str((B % 10) + j))\n A.append(a)\n L1 = L2\n L2 = len(A.copy())\nprint(A[K-1])"]
['Wrong Answer', 'Accepted']
['s384856332', 's910559056']
[13200.0, 12864.0]
[276.0, 260.0]
[3176, 739]
p02720
u350997995
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K = int(input())\nA = "0123456789"\nS = [i for i in range(1,10)]\nQ = [str(i) for i in range(1,10)]\nwhile Q:\n q = Q.pop(0)\n D = []\n if q[-1]=="0":\n D = [q+"0",q+"1"]\n elif q[-1]=="9":\n D = [q+"0",q+"1"]\n else:\n a = A.index(q[-1])\n D = [q+A[a-1],q+A[a],q+A[a+1]]\n for d in D:\n S.append(int(d))\n if len(d)<11:\n Q.append(d)\nS.sort()\nprint(S[K-1])', 'K = int(input())\nA = "0123456789"\nS = []\ndef f(n):\n global A,S\n if len(n)>10:return\n if n[-1]=="0":\n D=(n+"0",n+"1")\n elif n[-1]=="9":\n D=(n+"9",n+"8")\n else:\n a = A.index(n[-1])\n D=(n+A[a],n+A[a-1],n+A[a+1])\n for d in D:\n S.append(int(d))\n f(d)\n\nfor i in range(1,10):\n S.append(i)\n f(str(i))\nS.sort()\nprint(S[K-1])']
['Time Limit Exceeded', 'Accepted']
['s881060674', 's834102475']
[21096.0, 28184.0]
[2109.0, 509.0]
[411, 381]
p02720
u354126779
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k=int(input())\nA=[[1,1,1,1,1,1,1,1,1,1]]\nfor i in range(9):\n Ai=[]\n Ai.append(A[i][0]+A[i][1])\n for j in range(8):\n Ai.append(A[i][j]+A[i][j+1]+A[i][j+2])\n Ai.append(A[i][7]+A[i][8])\n A.append(Ai)\nc=[]\nfor i in range(len(A)):\n c.append(sum(A[i][1:10]))\nl=1 #length of number\nwhile k>c[l-1]:\n k=k-c[l-1]\n l+=1\nseq=[]\n\nn=1 \nwhile k>A[l-1][n]:\n k=k-A[l-1][n]\n n+=1\nseq.append(n)#head number\n\nfor i in range(l-1):\n if seq[i]==0:\n j=0\n while k>A[l-2-i][j]:\n k=k-A[l-2-i][j]\n j+=1\n seq.append(j)\n else:\n j=seq[i]-1\n while k>A[l-2-i][j]:\n k=k-A[l-2-i][j]\n j+=1 \n seq.append(j)\n\nfor i in range(len(seq)):\n print(seq[i],end="")', 'k=int(input())\nA=[[1,1,1,1,1,1,1,1,1,1]]\nfor i in range(9):\n Ai=[]\n Ai.append(A[i][0]+A[i][1])\n for j in range(8):\n Ai.append(A[i][j]+A[i][j+1]+A[i][j+2])\n Ai.append(A[i][7]+A[i][8])\n A.append(Ai)\nc=[]\nfor i in range(len(A)):\n c.append(sum(A[i][1:10]))\n\nprint(c)\nl=1 #length of number\nwhile k>c[l-1]:\n k=k-c[l-1]\n l+=1\nseq=[]\n\nn=1 \nwhile k>A[l-1][n]:\n k=k-A[l-1][n]\n n+=1\nseq.append(n)#head number\n\nfor i in range(l-1):\n if seq[i]==0:\n j=0\n while k>A[l-2-i][j]:\n k=k-A[l-2-i][j]\n j+=1\n seq.append(j)\n else:\n j=seq[i]-1\n while k>A[l-2-i][j]:\n k=k-A[l-2-i][j]\n j+=1 \n seq.append(j)\n\nfor i in range(len(seq)):\n print(seq[i],end="")', 'import queue\n\nk=int(input())\n\nq=queue.Queue()\n\nfor i in range(9):\n q.put(i+1)\n\nc=1\n\nfor i in range(k):\n c=q.get()\n b=c%10\n if b!=0:\n q.put(10*c+b-1)\n q.put(10*c+b)\n if b!=9:\n q.put(10*c+b+1)\n\nprint(c)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s880125695', 's962301671', 's655455544']
[3064.0, 3064.0, 12480.0]
[17.0, 17.0, 1015.0]
[757, 767, 232]
p02720
u354492470
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k = int(input())\n\nque = [1,2,3,4,5,6,7,8,9]\n\nfor i in range(k):\n x = que[0]\n del que[0]\n if x%10 != 0:\n que.append(10*x+(x%10)-1)\n que.append(10*x+(x%10))\n if x%10 != 9:\n que.append(10*x+(x%10)+1)\n print(x)', 'from collections import deque\nk = int(input())\nq = deque(list(range(1, 10)))\nfor _ in range(k-1):\n\td = q.popleft()\n\tif d%10 > 0:\n\t\tq.append(d*10 + d%10 - 1)\n\tq.append(d*10 + d%10)\n\tif d%10 < 9:\n\t\tq.append(d*10 + d%10 + 1)\nprint(q.popleft())']
['Wrong Answer', 'Accepted']
['s217497314', 's714428397']
[11760.0, 11912.0]
[2104.0, 131.0]
[238, 240]
p02720
u359178469
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K=int(input())\nA=[1,2,3,4,5,6,7,8,9]\nI=0\nwhile I<=K:\n if not A[I]%10==0:\n A.append(A[I]%10+10*A[I]-1)\n A.append(A[I]%10+10*A[I])\n if not A[I]%10==9:\n A.append(A[I]%10+10*A[I]+1)\n I+=1\n if len(A)>=K:\n break\nprint(A[I])', 'K=int(input())\nA=[1,2,3,4,5,6,7,8,9]\nI=0\nwhile I<=K:\n if not A[I]%10==0:\n A.append(A[I]%10+10*A[I]-1)\n A.append(A[I]%10+10*A[I])\n if not A[I]%10==9:\n A.append(A[I]%10+10*A[I]+1)\n I+=1\n if len(A)>=K:\n break\nprint(A[I])', 'K=int(input())\nA=[1,2,3,4,5,6,7,8,9]\nI=0\nwhile I<=K:\n if not A[I]%10==0:\n A.append(A[I]%10+10*A[I]-1)\n A.append(A[I]%10+10*A[I])\n if not A[I]%10==9:\n A.append(A[I]%10+10*A[I]+1)\n if len(A)>=K:\n break\n I+=1\nprint(A[K-1])']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s196349068', 's446102488', 's291342808']
[7228.0, 7228.0, 7216.0]
[69.0, 66.0, 71.0]
[251, 251, 253]
p02720
u375253797
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import math\n\nnum = int(input())\n\nbox = [1,2,3,4,5,6,7,8,9]\nk=0\n\nwhile True:\n \n if len(box)==num:\n print(box[num-1])\n break\n\n k = k+1 \n k1 = str(k)\n for i in range(len(k1)-1):\n if i == len(k1)-2:\n if abs(int(k1[i])-int(k1[i+1]))<=1:\n box.append(k)\n if abs(int(k1[i])-int(k1[i+1]))<=1:\n continue\n else:break\n\nprint(box)\n', 'a = [1,2,3,4,5,6,7,8,9]\ni = -1\nN = int(input())\n\nwhile True:\n if len(a) >= N:\n print(a[N-1])\n break\n i = i + 1\n n = int(str(a[i])[-1])\n x = a[i]*10 + n-1\n y = a[i]*10 + n\n z = a[i]*10 + n+1\n if n != 9 and n != 0:\n w = (x,y,z)\n a.extend(w)\n elif n == 9:\n w = (x,y)\n a.extend(w)\n elif n == 0:\n w = (y,z)\n a.extend(w)\n']
['Wrong Answer', 'Accepted']
['s060714390', 's608771075']
[3188.0, 7272.0]
[2104.0, 70.0]
[484, 399]
p02720
u377989038
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def dfs(r):\n global l\n if len(r) == 11:\n return\n l.append(int(r))\n for i in range(-1, 2):\n tmp = int(r[-1]) + i\n if 0 <= tmp <= 9:\n dfs(r + str(tmp))\n\n\nk = int(input())\nl = []\nfor i in range(1, 10):\n dfs(str(i))\nprint(sorted(l)[k])', 'def dfs(d, r):\n global l\n if d == 11:\n return\n l.append(int(r))\n for i in range(-1, 2):\n tmp = int(r[-1]) + i\n if 0 <= tmp <= 9:\n dfs(d + 1, r + str(tmp))\n\n\nk = int(input())\nl = []\nfor i in range(1, 10):\n dfs(1, str(i))\nprint(sorted(l)[k - 1])']
['Wrong Answer', 'Accepted']
['s171501051', 's370945622']
[12856.0, 12856.0]
[586.0, 556.0]
[278, 290]
p02720
u391675400
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import heapq\n\nk = int(input())\n\nlunlun = [1,2,3,4,5,6,7,8,9]\nheapq.heapify(lunlun)\n\nfor i in range(1,10**5):\n x = heapq.heappop(lunlun) \n y = x % 10\n if i == k :\n break\n if y != 0:\n heapq.heappush(lunlun, x * 10 + y- 1)\n heapq.heappush(lunlun,10*x+y)\n if y != 9:\n heapq.heappush(lunlun, x * 10 + y + 1)\nprint(lunlun)\nprint(x)\n\n', 'import heapq\n\nk = int(input())\ni=0\nlunlun = [1,2,3,4,5,6,7,8,9]\nheapq.heapify(lunlun)\n\nwhile True:\n i += 1\n if i == k:\n break\n x = heapq.heappop(lunlun)\n if x % 10 != 0:\n heapq.heappush(lunlun,10 * x + (x % 10) -1)\n heapq.heappush(lunlun,10 * x + (x % 10))\n if x % 10 != 9:\n heapq.heappush(lunlun,10 * x + (x % 10) +1)\n\nprint(lunlun[0])']
['Wrong Answer', 'Accepted']
['s771243772', 's877989991']
[18688.0, 11748.0]
[205.0, 194.0]
[377, 375]
p02720
u396210538
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['# from sys import stdin\nimport sys\nglobal cnt1\n\n\ndef bts(A, cnt, max):\n # print(A)\n if cnt == max:\n global cnt1\n cnt1 = cnt1+1\n if cnt1 == K:\n print(A)\n sys.exit()\n return\n cnt = cnt+1\n if A % 10 == 0:\n bts(A*10+(A % 10), cnt, max)\n bts(A*10+(A % 10)+1, cnt, max)\n elif A % 10 == 9:\n bts(A*10+(A % 10)-1, cnt, max)\n bts(A*10+(A % 10), cnt, max)\n else:\n bts(A*10+(A % 10)-1, cnt, max)\n bts(A*10+(A % 10), cnt, max)\n bts(A*10+(A % 10)+1, cnt, max)\n\n\nK = int(input())\n\nN = 9\nA = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n# global cnt1\ncnt1 = 9\nfor i in range(len(A)):\n bts(A[i], 1, 100)\n# print(cnt1)\n', '# from sys import stdin\nimport sys\nglobal cnt1\n\n\ndef bts(A, cnt, max):\n # print(A)\n if cnt == max:\n global cnt1\n cnt1 = cnt1+1\n if cnt1 == K:\n print(A)\n sys.exit()\n return\n cnt = cnt+1\n if A % 10 == 0:\n bts(A*10+(A % 10), cnt, max)\n bts(A*10+(A % 10)+1, cnt, max)\n elif A % 10 == 9:\n bts(A*10+(A % 10)-1, cnt, max)\n bts(A*10+(A % 10), cnt, max)\n else:\n bts(A*10+(A % 10)-1, cnt, max)\n bts(A*10+(A % 10), cnt, max)\n bts(A*10+(A % 10)+1, cnt, max)\n\n\nK = int(input())\n\nN = 9\nA = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n# global cnt1\ncnt1 = 9\nfor i in range(len(A)):\n bts(A[i], 1, 10)\n# print(cnt1)\n', '# from sys import stdin\nimport sys\nglobal cnt1\n\n\ndef bts(A, cnt, max):\n # print(A)\n if cnt == max:\n global cnt1\n cnt1 = cnt1+1\n if cnt1 == K:\n print(A)\n sys.exit()\n return\n cnt = cnt+1\n if A % 10 == 0:\n bts(A*10+(A % 10), cnt, max)\n bts(A*10+(A % 10)+1, cnt, max)\n elif A % 10 == 9:\n bts(A*10+(A % 10)-1, cnt, max)\n bts(A*10+(A % 10), cnt, max)\n else:\n bts(A*10+(A % 10)-1, cnt, max)\n bts(A*10+(A % 10), cnt, max)\n bts(A*10+(A % 10)+1, cnt, max)\n\n\nK = int(input())\n\nN = 9\nA = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n# global cnt1\ncnt1 = 0\nfor k in range(1, 11):\n for i in range(len(A)):\n bts(A[i], 1, k)\n# print(cnt1)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s147030259', 's149217060', 's470379012']
[3188.0, 3064.0, 3188.0]
[2104.0, 91.0, 71.0]
[714, 713, 743]
p02720
u408620326
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import sys\nsys.setrecursionlimit(10 ** 6)\ninput = sys.stdin.readline\nK = int(input())\nRUN = {\n 0:[0, 1],\n 1:[0, 1, 2],\n 2:[1, 2, 3],\n 3:[2, 3, 4],\n 4:[3, 4, 5],\n 5:[4, 5, 6],\n 6:[5, 6, 7],\n 7:[6, 7, 8],\n 8:[7, 8, 9],\n 9:[8, 9]\n}\ncnt = 0\n\ndef dfs(i, s, p):\n if i == 0:\n cnt = cnt + 1\n if cnt == K:\n print(s)\n exit()\n if s == 0:\n for ii in range(10):\n dfs(i-1, s+ii*10**(i-1), ii)\n else:\n for ii in RUN[p]:\n dfs(i-1, s+ii*10**(i-1), ii)\n\ndfs(10, 0, 0)', 'import sys\nsys.setrecursionlimit(10 ** 6)\ninput = sys.stdin.readline\nK = int(input())\nRUN = {\n 0:[0, 1],\n 1:[0, 1, 2],\n 2:[1, 2, 3],\n 3:[2, 3, 4],\n 4:[3, 4, 5],\n 5:[4, 5, 6],\n 6:[5, 6, 7],\n 7:[6, 7, 8],\n 8:[7, 8, 9],\n 9:[8, 9]\n}\ncnt = 0\n\ndef dfs(i, s, p):\n if i == 0:\n cnt = cnt + 1\n if cnt == K:\n print(s)\n exit()\n if s == 0:\n for ii in range(10):\n dfs(i-1, s+ii*10**(i-1), ii)\n else:\n for ii in RUN[p]:\n dfs(i-1, s+ii*10**(i-1), ii)\n\ndfs(10, 0, 0)', 'import sys\nsys.setrecursionlimit(10 ** 6)\ninput = sys.stdin.readline\nK = int(input())\nRUN = {\n 0:[0, 1],\n 1:[0, 1, 2],\n 2:[1, 2, 3],\n 3:[2, 3, 4],\n 4:[3, 4, 5],\n 5:[4, 5, 6],\n 6:[5, 6, 7],\n 7:[6, 7, 8],\n 8:[7, 8, 9],\n 9:[8, 9]\n}\ncnt = -1\n\ndef dfs(i, s, p, cnt):\n if i == 0:\n cnt += 1\n if cnt == K:\n print(s)\n exit()\n else:\n return cnt\n if s == 0:\n for ii in range(10):\n cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)\n else:\n for ii in RUN[p]:\n cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)\n\n return cnt\n\ndfs(10, 0, 0, cnt)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s234458864', 's284614854', 's966272511']
[3064.0, 3064.0, 3064.0]
[18.0, 18.0, 78.0]
[560, 560, 641]
p02720
u432098488
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import queue\n\nK = int(input())\nA = queue.Queue()\n\nfor i in range(1, 10):\n A.put(i)\n\nnum = 0\nwhile num < K:\n emp = A.get()\n var = emp % 10\n if var != 0:\n A.put(emp*10+var-1)\n A.put(10*emp)\n if var != 9:\n A.put(emp*10+var+1)\n num += 1\n print(num, emp)\n\nprint(emp)', 'import queue\n\nK = int(input())\nA = queue.Queue()\n\nfor i in range(1, 10):\n A.put(i)\n\nnum = 0\nwhile num < K:\n emp = A.get()\n var = emp % 10\n if var != 0:\n A.put(emp*10+var-1)\n A.put(10*emp+var)\n if var != 9:\n A.put(emp*10+var+1)\n num += 1\n\nprint(emp)']
['Wrong Answer', 'Accepted']
['s406842319', 's444825920']
[12728.0, 12480.0]
[1141.0, 1069.0]
[347, 327]
p02720
u432754124
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\n\nk = int(input())\nq = deque(range(1, 10))\n\nfor i in range(k-1):\n \n x = q.popleft()\n y = int(str(x)[-1])\n if y-1 >= 0:\n print(int(str(x)+str(y-1)))\n q.append(int(str(x)+str(y-1)))\n q.append(int(str(x)+str(x)[-1]))\n if y+1 < 10:\n q.append(int(str(x)+str(y+1)))\n\n print(q)\n\n\n', 'from collections import deque\n\nk = int(input())\nq = deque(range(1, 10))\n\nfor i in range(k-1):\n \n x = q.popleft()\n y = int(str(x)[-1])\n if y-1 >= 0:\n q.append(int(str(x)+str(y-1)))\n q.append(int(str(x)+str(x)[-1]))\n if y+1 < 10:\n q.append(int(str(x)+str(y+1)))\n\nprint(q[0])\n\n\n']
['Runtime Error', 'Accepted']
['s187178571', 's547826545']
[137184.0, 16620.0]
[1573.0, 253.0]
[364, 327]
p02720
u437215432
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def f(k):\n def lunlun(n):\n s = [int(i) for i in str(n)]\n for i in range(len(s) - 1):\n if abs(s[i] - s[i + 1]) > 1:\n return False\n return True\n cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]\n for i, begin in enumerate(cum_npi):\n if k < begin:\n begin = cum_npi[i-1]\n break\n print(f"begin = {begin}")\n found = begin\n while found != k:\n begin += 1\n if lunlun(begin):\n found += 1\n if found == k:\n break\n print(begin)\n\nf(int(input()))\n', 'def f(k):\n def lunlun(n):\n s = [int(i) for i in str(n)]\n for i in range(len(s) - 1):\n if abs(s[i] - s[i + 1]) > 1:\n return False\n return True\n i = 0\n while k > 0:\n i += 1\n if lunlun(i):\n k -= 1\n print(i)\n\nf(int(input())\n', 'def f(k):\n if 1 <= k <= 9:\n print(k)\n else:\n nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]\n cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]\n for length, begin in enumerate(cum_npi):\n if k < begin:\n found = cum_npi[length - 1]\n break\n begin = 10 ** (length - 1)\n # length, begin, found\n k -= found\n x = [[]] * (length + 1)\n x[1] = list(range(1, 10))\n # x\n\n terminate = False\n i = 1\n while True:\n \n if len(x[i]): # len(x[i])\n digit = x[i][0]\n if i < length: \n i += 1\n x[i] = nxt[digit].copy()\n \n \n if i == length: \n while len(x[i]): # i, x[i]\n k -= 1\n \n if k == 0:\n x.pop(0)\n #print("answer =", x)\n ans = "".join([str(j.pop(0)) for j in x])\n print(ans)\n terminate = True\n break\n else:\n x[i].pop(0)\n \n else:\n \n while len(x[i]) == 0:\n i -= 1\n x[i].pop(0)\n if terminate:\n break\n\nf(int(input()))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s496179032', 's731089252', 's478514242']
[2940.0, 2940.0, 9320.0]
[17.0, 17.0, 34.0]
[600, 304, 1969]
p02720
u440161695
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\nK=int(input())\nd=deque([_ for _ in range(1,10)])\nif K<=9:\n print(K)\n exit()\ni=0\nwhile True:\n a=d.pop()\n i+=1\n if i==K:\n print(a)\n exit()\n if a%10!=0 and a%10!=9:\n d.extend([10*a+(a%10)+i for i in range(-1,2)])\n elif a%10==0:\n d.extend([10*a+i for i in range(2)])\n else:\n d.extend([10*a+i for i in range(-1,2)])', 'from collections import deque\nK=int(input())\nd=deque([_ for _ in range(1,10)])\nif K<=9:\n print(K)\n exit()\ni=0\nwhile True:\n a=d.popleft()\n i+=1\n if i==K:\n print(a)\n exit()\n if a%10!=0 and a%10!=9:\n d.extend([10*a+(a%10)+i for i in range(-1,2)])\n elif a%10==0:\n d.extend([10*a+i for i in range(2)])\n elif a%10==9:\n d.extend([10*a+i for i in range(8,10)])']
['Wrong Answer', 'Accepted']
['s997295777', 's682209863']
[529636.0, 12008.0]
[2137.0, 193.0]
[365, 377]
p02720
u459150945
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K = int(input())\nimport sys\nsys.setrecursionlimit(1000000)\nrun = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\n\ndef runrun(number):\n if len(number) < 16:\n last = int(number[-1])\n if last == 0:\n run.append(int(str(int(number[-1])+0)))\n run.append(int(str(int(number[-1])+1)))\n runrun(str(int(number[-1])+0))\n runrun(str(int(number[-1])+1))\n elif last == 9:\n run.append(int(str(int(number[-1])+0)))\n run.append(int(str(int(number[-1])-1)))\n runrun(str(int(number[-1])+0))\n runrun(str(int(number[-1])-1))\n else:\n run.append(int(str(int(number[-1])+0)))\n run.append(int(str(int(number[-1])-1)))\n run.append(int(str(int(number[-1])+1)))\n runrun(str(int(number[-1])+0))\n runrun(str(int(number[-1])+1))\n runrun(str(int(number[-1])-1))\n\n\nfor i in range(1, 10):\n runrun(str(i))\nrun.sort(reverse=False)\n\n\nprint(run[K-1])', 'from collections import deque\nK = int(input())\nque = deque(list(range(1, 10)))\nfor i in range(K):\n x = que.popleft()\n last = x % 10\n if last != 0:\n que.append(x*10 + last-1)\n que.append(x*10 + last)\n if last != 9:\n que.append(x*10 + last+1)\nprint(x)\n']
['Time Limit Exceeded', 'Accepted']
['s303259777', 's783390797']
[481672.0, 11956.0]
[2138.0, 110.0]
[1015, 279]
p02720
u461454424
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['#input\nK = int(input())\n\n#output\nq = queue.Queue()\nfor i in range(1, 10):\n q.put(i)\n\nfor i in range(1, K+2):\n x = q.get()\n if x % 10 != 0:\n q.put(10*x + (x % 10)-1)\n q.put(10*x+(x % 10))\n if x % 10 != 9:\n q.put(10*x + (x % 10)+1)\n if i == K:\n print(x)', 'import queue\n\n#input\nK = int(input())\n\n#output\nq = queue.Queue()\nfor i in range(1, 10):\n q.put(i)\n\nfor i in range(1, K+2):\n x = q.get()\n if x % 10 != 0:\n q.put(10*x + (x % 10)-1)\n q.put(10*x+(x % 10))\n if x % 10 != 9:\n q.put(10*x + (x % 10)+1)\n if i == K:\n print(x)']
['Runtime Error', 'Accepted']
['s669430329', 's071587285']
[3064.0, 12452.0]
[17.0, 1055.0]
[290, 304]
p02720
u471641802
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K = int(input())\n\nqueue = list(range(1, 10))\n\nif K < 10:\n print(K)\nelse:\n i = 0\n while K > len(queue):\n if queue[i] % 10 != 0:\n l = 10 * queue[i] + queue[i] % 10 - 1\n queue.append(l)\n \n l = 10 * queue[i] + queue[i] % 10\n queue.append(l)\n \n if queue[i] % 10 != 9:\n l = 10 * queue[i] + queue[i] % 10 + 1\n queue.append(l)\n \n i += 1\n\n print(queue[K])', 'K = int(input())\n\nqueue = list(range(1, 10))\n\nif K < 10:\n print(K)\nelse:\n i = 0\n while K > len(queue):\n if queue[i] % 10 != 0:\n l = 10 * queue[i] + queue[i] % 10 - 1\n queue.append(l)\n \n l = 10 * queue[i] + queue[i] % 10\n queue.append(l)\n \n if queue[i] % 10 != 9:\n l = 10 * queue[i] + queue[i] % 10 + 1\n queue.append(l)\n \n i += 1\n\n print(queue[K - 1])']
['Runtime Error', 'Accepted']
['s904876237', 's513272272']
[7200.0, 7200.0]
[66.0, 64.0]
[458, 462]
p02720
u479638406
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import copy\nk = int(input())\n\ncnt = 0\nfor i in range(1, 100000):\n if i < 9:\n cnt += 1\n else:\n num = copy.copy(i)\n nei = []\n while num < 10:\n nei.append(num%10)\n num /= 10\n for j in range(len(nei)):\n if abs(nei[j] - nei[j+1]) > 1:\n break\n elif abs(nei[j] - nei[j+1]) <= 1 and nei[j] == nei[len(nei)-1]:\n cnt += 1\n \n if cnt == k:\n print(i)\n break', 'from queue import Queue\nq = Queue()\n\nk = int(input())\n\nfor i in range(9):\n q.put(i+1)\nfor _ in range(k-1):\n x = q.get()\n mod = x%10\n \n if x%10 != 0:\n q.put(10*x + mod - 1)\n \n q.put(10*x + mod)\n \n if x%10 != 9:\n q.put(10*x + mod + 1)\n \nprint(q.get())']
['Time Limit Exceeded', 'Accepted']
['s937966202', 's456168145']
[227068.0, 12476.0]
[2118.0, 1068.0]
[409, 291]
p02720
u484052148
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\nK = int(input())\nq = deque(str(i) for i in range(1, 10))\ncnt = 9\nif K < 10:\n print(K); return\nwhile True:\n tmp = q.popleft()\n las = int(tmp[-1])\n for i in range(las-1, las+2):\n if 0<=i<=9:\n q.append(tmp + str(i))\n cnt += 1\n if cnt==K:\n print(q.pop()); return', 'from numba import jit\n\n@njit\ndef resolve():\n\tfrom collections import deque\n\tK = int(input())\n\tq = deque(str(i) for i in range(1, 10))\n\tcnt = 9\n\tif K < 10:\n\t\tprint(K); return\n\twhile True:\n\t\ttmp = q.popleft()\n\t\tlas = int(tmp[-1])\n\t\tfor i in range(las-1, las+2):\n\t\t\tif 0<=i<=9:\n\t\t\t\tq.append(tmp + str(i))\n\t\t\t\tcnt += 1\n\t\t\t\tif cnt==K:\n\t\t\t\t\tprint(q.pop()); return\nresolve()', 'def resolve():\n\tfrom collections import deque\n\tK = int(input())\n\tq = deque(str(i) for i in range(1, 10))\n\tcnt = 9\n\tif K < 10:\n\t\tprint(K); return\n\twhile True:\n\t\ttmp = q.popleft()\n\t\tlas = int(tmp[-1])\n\t\tfor i in range(las-1, las+2):\n\t\t\tif 0<=i<=9:\n\t\t\t\tq.append(tmp + str(i))\n\t\t\t\tcnt += 1\n\t\t\t\tif cnt==K:\n\t\t\t\t\tprint(q.pop()); return\nresolve()']
['Runtime Error', 'Runtime Error', 'Accepted']
['s049296115', 's323573796', 's525691490']
[9092.0, 91680.0, 13712.0]
[25.0, 389.0, 73.0]
[355, 367, 338]
p02720
u502841298
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["n = int(input())\nD = []\n\ndef FindOtvet(i, j, otv):\n if i == 0:\n return ''\n if j == 0:\n if (otv + D[i - 1][j]) < n:\n otv += D[i - 1][j]\n return str(j + 1) + FindOtvet(i - 1, j + 1, otv)\n else:\n return str(j) + FindOtvet(i - 1, j, otv)\n elif j == 9:\n if (otv + D[i - 1][j - 1]) < n:\n otv += D[i - 1][j - 1]\n return str(j) + FindOtvet(i - 1, j, otv)\n else:\n return str(j - 1) + FindOtvet(i - 1, j - 1, otv)\n else:\n if (otv + D[i - 1][j - 1]) < n:\n otv += D[i - 1][j - 1]\n if (otv + D[i - 1][j]) < n:\n otv += D[i - 1][j]\n return str(j + 1) + FindOtvet(i - 1, j + 1, otv)\n else:\n return str(j) + FindOtvet(i - 1, j, otv)\n else:\n return str(j - 1) + FindOtvet(i - 1, j - 1, otv)\n\narr = []\nfor i in range(10):\n arr.append(1)\nD.append(arr)\ntotalSum = 9\ni = 1\nrespI = 0\nrespJ = 0\nwhile respI == 0 and respJ == 0:\n arr = []\n for j in range(10):\n if j == 0:\n arr.append(D[i - 1][j] + D[i - 1][j + 1])\n elif j < 9:\n arr.append(D[i - 1][j - 1] + D[i - 1][j] + D[i - 1][j + 1])\n else:\n arr.append(D[i - 1][j - 1] + D[i - 1][j])\n if j > 0:\n if (totalSum + arr[j]) >= n:\n respI = i\n respJ = j\n break\n totalSum += arr[j]\n D.append(arr)\n i += 1\nprint(*D)\nrespStr = str(respJ)\nprint(respStr + FindOtvet(respI, respJ, totalSum))\n", "n = int(input())\nD = []\n\ndef FindOtvet(i, j, otv):\n if i == 0:\n return ''\n if j == 0:\n if (otv + D[i - 1][j]) < n:\n otv += D[i - 1][j]\n return str(j + 1) + FindOtvet(i - 1, j + 1, otv)\n else:\n return str(j) + FindOtvet(i - 1, j, otv)\n elif j == 9:\n if (otv + D[i - 1][j - 1]) < n:\n otv += D[i - 1][j - 1]\n return str(j) + FindOtvet(i - 1, j, otv)\n else:\n return str(j - 1) + FindOtvet(i - 1, j - 1, otv)\n else:\n if (otv + D[i - 1][j - 1]) < n:\n otv += D[i - 1][j - 1]\n if (otv + D[i - 1][j]) < n:\n otv += D[i - 1][j]\n return str(j + 1) + FindOtvet(i - 1, j + 1, otv)\n else:\n return str(j) + FindOtvet(i - 1, j, otv)\n else:\n return str(j - 1) + FindOtvet(i - 1, j - 1, otv)\n\narr = []\nif n < 10:\n print(n)\n exit()\nfor i in range(10):\n arr.append(1)\nD.append(arr)\ntotalSum = 9\ni = 1\nrespI = 0\nrespJ = 0\nwhile respI == 0 and respJ == 0:\n arr = []\n for j in range(10):\n if j == 0:\n arr.append(D[i - 1][j] + D[i - 1][j + 1])\n elif j < 9:\n arr.append(D[i - 1][j - 1] + D[i - 1][j] + D[i - 1][j + 1])\n else:\n arr.append(D[i - 1][j - 1] + D[i - 1][j])\n if j > 0:\n if (totalSum + arr[j]) >= n:\n respI = i\n respJ = j\n break\n totalSum += arr[j]\n D.append(arr)\n i += 1\nrespStr = str(respJ)\nprint(respStr + FindOtvet(respI, respJ, totalSum))\n"]
['Wrong Answer', 'Accepted']
['s387866822', 's974096800']
[3192.0, 3192.0]
[18.0, 18.0]
[1568, 1593]
p02720
u507613674
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\n\nstdin = sys.stdin\nread_int = lambda : list(map(int,stdin.readline().split()))\n\nK = read_int()[0]\n\nq = deque()\nfor i in range(1, 10):\n q.append(i)\ndef solve():\n for _ in range(K - 1):\n x = q.popleft()\n if x % 10 != 0:\n q.append(10 * x + (x % 10 - 1))\n q.append(10 * x + (x % 10))\n if x % 10 != 9:\n q.append(10 * x + + (x % 10 + 1))\n print()\n return q.popleft()\n\nif __name__ == "__main__":\n print(solve())', 'from collections import deque\nimport sys\n\nstdin = sys.stdin\nread_int = lambda : list(map(int,stdin.readline().split()))\n\nK = read_int()[0]\n\nq = deque()\nfor i in range(1, 10):\n q.append(i)\n\ndef solve():\n for _ in range(K - 1):\n x = q.popleft()\n if x % 10 != 0:\n q.append(10 * x + (x % 10 - 1))\n q.append(10 * x + (x % 10))\n if x % 10 != 9:\n q.append(10 * x + + (x % 10 + 1))\n return q.popleft()\n\nif __name__ == "__main__":\n print(solve())']
['Runtime Error', 'Accepted']
['s073239522', 's551348036']
[3316.0, 12384.0]
[21.0, 105.0]
[499, 499]
p02720
u509739538
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import math\nimport queue\n\ndef readInt():\n\treturn int(input())\n\ndef readInts():\n\treturn list(map(int, input().split()))\n\ndef readChars():\n\treturn input().split()\n\n\nq = queue.Queue()\n\nfor i in range(1,9):\n\tq.put(i)\n\nn = readInt()\n\nfor i in range(1,100000):\n\ta = str(q.get())\n\tif a[-1]!=0:\n\t\tq.put(int(a + str( int(a[-1])-1)))\n\tq.put(int(a+str(str(int(a[-1])))))\n\tif a[-1]!=9:\n\t\tq.put(int(a+str(int(a[-1])+1)))\t\n\tif i==n:\n\t\tprint(q.get())\n\t\tbreak', 'import math\nimport queue\n\ndef readInt():\n\treturn int(input())\n\ndef readInts():\n\treturn list(map(int, input().split()))\n\ndef readChars():\n\treturn input().split()\n\n\nq = queue.Queue()\n\nfor i in range(1,9):\n\tq.put(i)\n\nn = readInt()\n\nfor i in range(1,100000):\n\ta = str(q.get())\n\tif a[-1]!=0:\n\t\tq.put(int(a+str(int(a[-1])-1)))\n\tq.put(int(a+str(str(int(a[-1])))))\n\tif a[-1]!=9:\n\t\tq.put(int(a+str(int(a[-1])+1)))\t\n\tif i==n:\n\t\tprint(q.get())\n\t\tbreak', 'def jud(n1,n2):\n\tif abs(n1-int(str(n2)[0]))<=1:\n\t\treturn 1\n\telse:\n\t\treturn 0\n\nrnrn = [[1,2,3,4,5,6,7,8,9],[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99]]\n\nfor div in range(1,10):\n\trnrn.append([])\n\tfor i in range(len(rnrn[div])):\n\t\ty = str(rnrn[div][i])\n\t\tx = int(y[-1])\n\t\tif x-1!=-1:\n\t\t\trnrn[div+1].append(int(y+str(x-1)))\n\t\trnrn[div+1].append(int(y+str(x)))\n\t\tif x+1!=10:\n\t\t\trnrn[div+1].append(int(y+str(x+1)))\n\t\t\nrnrn2 = []\nfor i in range(len(rnrn)):\n\trnrn2.extend(rnrn[i])\n\nprint(rnrn2)', 'def jud(n1,n2):\n\tif abs(n1-int(str(n2)[0]))<=1:\n\t\treturn 1\n\telse:\n\t\treturn 0\n\nrnrn = [[1,2,3,4,5,6,7,8,9],[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99]]\n\nfor div in range(1,12):\n\trnrn.append([])\n\tfor i in range(len(rnrn[div])):\n\t\ty = str(rnrn[div][i])\n\t\tx = int(y[-1])\n\t\tif x-1!=-1:\n\t\t\trnrn[div+1].append(int(y+str(x-1)))\n\t\trnrn[div+1].append(int(y+str(x)))\n\t\tif x+1!=10:\n\t\t\trnrn[div+1].append(int(y+str(x+1)))\n\t\t\nrnrn2 = []\nfor i in range(len(rnrn)):\n\trnrn2.extend(rnrn[i])\n\nprint(rnrn2[int(input())])', 'def jud(n1,n2):\n\tif abs(n1-int(str(n2)[0]))<=1:\n\t\treturn 1\n\telse:\n\t\treturn 0\n\nrnrn = [[1,2,3,4,5,6,7,8,9],[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99],\n[100,101,110, 111, 112, 121, 122, 123, 210, 211, 212, 221, 222, 223, 232, 233, 234, 321, 322, 323, 332, 333, 334, 343, 344, 345, 432, 433, 434, 443, 444, 445, 454, 455, 456, 543, 544, 545, 554, 555, 556, 565, 566, 567, 654, 655, 656, 665, 666, 667, 676, 677, 678, 765, 766, 767, 776, 777, 778, 787, 788, 789, 876, 877, 878, 887, 888, 889, 898, 899, 987, 988, 989, 998, 999],\n[1000,1001,1010,1011,1100, 1101, 1110, 1111, 1112, 1121, 1122, 1123, 1210, 1211, 1212, 1221, 1222, 1223, 1232, 1233, 1234, 2100, 2101, 2110, 2111, 2112, 2121, 2122, 2123, 2210, 2211, 2212, 2221, 2222, 2223, 2232, 2233, 2234, 2321, 2322, 2323, 2332, 2333, 2334, 2343, 2344, 2345, 3210, 3211, 3212, 3221, 3222, 3223, 3232, 3233, 3234, 3321, 3322, 3323, 3332, 3333, 3334, 3343, 3344, 3345, 3432, 3433, 3434, 3443, 3444, 3445, 3454, 3455, 3456, 4321, 4322, 4323, 4332, 4333, 4334, 4343, 4344, 4345, 4432, 4433, 4434, 4443, 4444, 4445, 4454, 4455, 4456, 4543, 4544, 4545, 4554, 4555, 4556, 4565, 4566, 4567, 5432, 5433, 5434, 5443, 5444, 5445, 5454, 5455, 5456, 5543, 5544, 5545, 5554, 5555, 5556, 5565, 5566, 5567, 5654, 5655, 5656, 5665, 5666, 5667, 5676, 5677, 5678, 6543, 6544, 6545, 6554, 6555, 6556, 6565, 6566, 6567, 6654, 6655, 6656, 6665, 6666, 6667, 6676, 6677, 6678, 6765, 6766, 6767, 6776, 6777, 6778, 6787, 6788, 6789, 7654, 7655, 7656, 7665, 7666, 7667, 7676, 7677, 7678, 7765, 7766, 7767, 7776, 7777, 7778, 7787, 7788, 7789, 7876, 7877, 7878, 7887, 7888, 7889, 7898, 7899, 8765, 8766, 8767, 8776, 8777, 8778, 8787, 8788, 8789, 8876, 8877, 8878, 8887, 8888, 8889, 8898, 8899, 8987, 8988, 8989, 8998, 8999, 9876, 9877, 9878, 9887, 9888, 9889, 9898, 9899, 9987, 9988, 9989, 9998, 9999],\n[10001,10010,10011,10100,10101,10110,10111,11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 11112, 11121, 11122, 11123, 11210, 11211, 11212, 11221, 11222, 11223, 11232, 11233, 11234, 12100, 12101, 12110, 12111, 12112, 12121, 12122, 12123, 12210, 12211, 12212, 12221, 12222, 12223, 12232, 12233, 12234, 12321, 12322, 12323, 12332, 12333, 12334, 12343, 12344, 12345, 21000, 21001, 21010, 21011, 21100, 21101, 21110, 21111, 21112, 21121, 21122, 21123, 21210, 21211, 21212, 21221, 21222, 21223, 21232, 21233, 21234, 22100, 22101, 22110, 22111, 22112, 22121, 22122, 22123, 22210, 22211, 22212, 22221, 22222, 22223, 22232, 22233, 22234, 22321, 22322, 22323, 22332, 22333, 22334, 22343, 22344, 22345, 23210, 23211, 23212, 23221, 23222, 23223, 23232, 23233, 23234, 23321, 23322, 23323, 23332, 23333, 23334, 23343, 23344, 23345, 23432, 23433, 23434, 23443, 23444, 23445, 23454, 23455, 23456, 32100, 32101, 32110, 32111, 32112, 32121, 32122, 32123, 32210, 32211, 32212, 32221, 32222, 32223, 32232, 32233, 32234, 32321, 32322, 32323, 32332, 32333, 32334, 32343, 32344, 32345, 33210, 33211, 33212, 33221, 33222, 33223, 33232, 33233, 33234, 33321, 33322, 33323, 33332, 33333, 33334, 33343, 33344, 33345, 33432, 33433, 33434, 33443, 33444, 33445, 33454, 33455, 33456, 34321, 34322, 34323, 34332, 34333, 34334, 34343, 34344, 34345, 34432, 34433, 34434, 34443, 34444, 34445, 34454, 34455, 34456, 34543, 34544, 34545, 34554, 34555, 34556, 34565, 34566, 34567, 43210, 43211, 43212, 43221, 43222, 43223, 43232, 43233, 43234, 43321, 43322, 43323, 43332, 43333, 43334, 43343, 43344, 43345, 43432, 43433, 43434, 43443, 43444, 43445, 43454, 43455, 43456, 44321, 44322, 44323, 44332, 44333, 44334, 44343, 44344, 44345, 44432, 44433, 44434, 44443, 44444, 44445, 44454, 44455, 44456, 44543, 44544, 44545, 44554, 44555, 44556, 44565, 44566, 44567, 45432, 45433, 45434, 45443, 45444, 45445, 45454, 45455, 45456, 45543, 45544, 45545, 45554, 45555, 45556, 45565, 45566, 45567, 45654, 45655, 45656, 45665, 45666, 45667, 45676, 45677, 45678, 54321, 54322, 54323, 54332, 54333, 54334, 54343, 54344, 54345, 54432, 54433, 54434, 54443, 54444, 54445, 54454, 54455, 54456, 54543, 54544, 54545, 54554, 54555, 54556, 54565, 54566, 54567, 55432, 55433, 55434, 55443, 55444, 55445, 55454, 55455, 55456, 55543, 55544, 55545, 55554, 55555, 55556, 55565, 55566, 55567, 55654, 55655, 55656, 55665, 55666, 55667, 55676, 55677, 55678, 56543, 56544, 56545, 56554, 56555, 56556, 56565, 56566, 56567, 56654, 56655, 56656, 56665, 56666, 56667, 56676, 56677, 56678, 56765, 56766, 56767, 56776, 56777, 56778, 56787, 56788, 56789, 65432, 65433, 65434, 65443, 65444, 65445, 65454, 65455, 65456, 65543, 65544, 65545, 65554, 65555, 65556, 65565, 65566, 65567, 65654, 65655, 65656, 65665, 65666, 65667, 65676, 65677, 65678, 66543, 66544, 66545, 66554, 66555, 66556, 66565, 66566, 66567, 66654, 66655, 66656, 66665, 66666, 66667, 66676, 66677, 66678, 66765, 66766, 66767, 66776, 66777, 66778, 66787, 66788, 66789, 67654, 67655, 67656, 67665, 67666, 67667, 67676, 67677, 67678, 67765, 67766, 67767, 67776, 67777, 67778, 67787, 67788, 67789, 67876, 67877, 67878, 67887, 67888, 67889, 67898, 67899, 76543, 76544, 76545, 76554, 76555, 76556, 76565, 76566, 76567, 76654, 76655, 76656, 76665, 76666, 76667, 76676, 76677, 76678, 76765, 76766, 76767, 76776, 76777, 76778, 76787, 76788, 76789, 77654, 77655, 77656, 77665, 77666, 77667, 77676, 77677, 77678, 77765, 77766, 77767, 77776, 77777, 77778, 77787, 77788, 77789, 77876, 77877, 77878, 77887, 77888, 77889, 77898, 77899, 78765, 78766, 78767, 78776, 78777, 78778, 78787, 78788, 78789, 78876, 78877, 78878, 78887, 78888, 78889, 78898, 78899, 78987, 78988, 78989, 78998, 78999, 87654, 87655, 87656, 87665, 87666, 87667, 87676, 87677, 87678, 87765, 87766, 87767, 87776, 87777, 87778, 87787, 87788, 87789, 87876, 87877, 87878, 87887, 87888, 87889, 87898, 87899, 88765, 88766, 88767, 88776, 88777, 88778, 88787, 88788, 88789, 88876, 88877, 88878, 88887, 88888, 88889, 88898, 88899, 88987, 88988, 88989, 88998, 88999, 89876, 89877, 89878, 89887, 89888, 89889, 89898, 89899, 89987, 89988, 89989, 89998, 89999, 98765, 98766, 98767, 98776, 98777, 98778, 98787, 98788, 98789, 98876, 98877, 98878, 98887, 98888, 98889, 98898, 98899, 98987, 98988, 98989, 98998, 98999, 99876, 99877, 99878, 99887, 99888, 99889, 99898, 99899, 99987, 99988, 99989, 99998, 99999]]\n\ndi = 4\n\nfor i in range(1,10):\n\tfor j in range(len(rnrn[3])):\n\t\tif(jud(i,rnrn[3][j])):\n\t\t\trnrn[4].append(int(str(i)+str(rnrn[3][j])))\n\nprint(rnrn)', 'import math\nimport queue\n\ndef readInt():\n\treturn int(input())\n\ndef readInts():\n\treturn list(map(int, input().split()))\n\ndef readChars():\n\treturn input().split()\n\n\nq = queue.Queue()\n\nfor i in range(1,10):\n\tq.put(i)\n\nn = readInt()\n\nfor i in range(1,100000):\n\ta = str(q.get())\n\tb = int(a[-1])\n\tprint(b)\n\tif b!=0:\n\t\tq.put(int(a+str(b-1)))\n\tq.put(int(a+str(b)))\n\tif b==9:\n\t\tq.put(int(a+str(b+1)))\t\n\tif i==n:\n\t\tprint(int(a))\n\t\tbreak', 'import math\nimport queue\nfrom collections import defaultdict\n \ndef readInt():\n\treturn int(input())\ndef readInts():\n\treturn list(map(int, input().split()))\ndef readChar():\n\treturn input()\ndef readChars():\n\treturn input().split()\ndef factorization(n):\n\tres = []\n\tif n%2==0:\n\t\tres.append(2)\n\tfor i in range(3,math.floor(n//2)+1,2):\n\t\tif n%i==0:\n\t\t\tc = 0\n\t\t\tfor j in res:\n\t\t\t\tif i%j==0:\n\t\t\t\t\tc=1\n\t\t\tif c==0:\n\t\t\t\tres.append(i)\n\treturn res\ndef fact2(n):\n\tp = factorization(n)\n\tres = []\n\tfor i in p:\n\t\tc=0\n\t\tz=n\n\t\twhile 1:\n\t\t\tif z%i==0:\n\t\t\t\tc+=1\n\t\t\t\tz/=i\n\t\t\telse:\n\t\t\t\tbreak\n\t\tres.append([i,c])\n\treturn res\ndef fact(n):\n\tans = 1\n\tm=n\n\tfor _i in range(n-1):\n\t\tans*=m\n\t\tm-=1\n\treturn ans\ndef comb(n,r):\n\tl = min(r,n-r)\n\tm=n\n\tu=1\n\tfor _i in range(l):\n\t\tu*=m\n\t\tm-=1\n\treturn u//fact(l)\ndef printQueue(q):\n\tr=q\n\tans=[0]*r.qsize()\n\tfor i in range(r.qsize()-1,-1,-1):\n\t\tans[i] = r.get()\n\tprint(ans)\n\n\nK = readInt()\n\nq = queue.Queue()\n\nfor i in range(1,10):\n\tq.put(i)\n\nans = 0\nfor i in range(K):\n\tans = q.get()\n\tif str(ans)[-1]=="0":\n\t\tq.put(int(str(ans)+"0"))\n\t\tq.put(int(str(ans)+"1"))\n\telif str(ans)[-1]=="9":\n\t\tq.put(int(str(ans)+"8"))\n\t\tq.put(int(str(ans)+"9"))\n\telse:\n\t\tq.put(int(str(ans)+str(int(str(ans)[-1])-1)))\n\t\tq.put(int(str(ans)+str(int(str(ans)[-1]))))\n\t\tq.put(int(str(ans)+str(int(str(ans)[-1])+1)))\n\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Time Limit Exceeded', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s049132696', 's264392214', 's340515339', 's465685465', 's808426047', 's856764890', 's464890100']
[3952.0, 3952.0, 52232.0, 93816.0, 3832.0, 7704.0, 11536.0]
[26.0, 27.0, 680.0, 2109.0, 21.0, 1055.0, 1435.0]
[443, 440, 522, 536, 6344, 426, 1342]
p02720
u517910772
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\n\n\ndef lunlun():\n k = int(input())\n q = deque(list(range(1, 10)))\n\n while k > 0:\n k -= 1\n n = q.popleft()\n # print(\'====== popleft:\', n)\n\n if n % 10 != 0:\n n0 = int(str(n) + str(n % 10 - 1))\n q.append(n0)\n # print(\'=== append:\', n0)\n\n n1 = int(str(n) + str(n % 10))\n q.append(n1)\n # print(\'=== append:\', n1)\n\n if n % 10 != 9:\n n2 = int(str(n) + str(n % 10 + 1))\n q.append(n2)\n # print(\'=== append:\', n2)\n\n print(\'answer:\', n)\n\n\n##########\nif __name__ == "__main__":\n lunlun()\n', 'from collections import deque\n\n\ndef lunlun():\n k = int(input())\n q = deque(list(range(1, 10)))\n\n while k > 0:\n k -= 1\n n = q.popleft()\n # print(\'====== popleft:\', n)\n\n if n % 10 != 0:\n n0 = int(str(n) + str(n % 10 - 1))\n q.append(n0)\n # print(\'=== append:\', n0)\n\n n1 = int(str(n) + str(n % 10))\n q.append(n1)\n # print(\'=== append:\', n1)\n\n if n % 10 != 9:\n n2 = int(str(n) + str(n % 10 + 1))\n q.append(n2)\n # print(\'=== append:\', n2)\n\n print(n)\n\n\n##########\nif __name__ == "__main__":\n lunlun()\n']
['Wrong Answer', 'Accepted']
['s588732862', 's639931705']
[10968.0, 10840.0]
[277.0, 268.0]
[642, 631]
p02720
u524922893
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import queue\nk=int(input())\nq=queue.Queue()\nfor i in range(1,10):\n q.put(i)\nc=0\nwhile c<k:\n a=q.get()\n c+=1\n print("{}番目:{}".format(c,a))\n if c==k:\n print(a)\n if (a%10)!=0:\n q.put(10*a+a%10-1)\n q.put(10*a+a%10)\n if (a%10)!=9:\n q.put(10*a+a%10+1)', 'import queue\nk=int(input())\nq=queue.Queue()\nfor i in range(1,10):\n q.put(i)\nc=0\nwhile c<k:\n a=q.get()\n c+=1\n if c==k:\n print(a)\n if (a%10)!=0:\n q.put(10*a+a%10-1)\n q.put(10*a+a%10)\n if (a%10)!=9:\n q.put(10*a+a%10+1)']
['Wrong Answer', 'Accepted']
['s400110506', 's992666970']
[14820.0, 12452.0]
[1339.0, 1063.0]
[266, 231]
p02720
u528748570
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import heapq\nl = [1, 2, 3, 4, 5, 6, 7, 8, 9]\nheapq.heapify(l)\n\ndef f(x):\n \n min_x = int(list(str(x))[-1])\n if min_x == 0:\n yield int(x + "0")\n yield int(x + "1")\n elif min_x == 9:\n yield int(x + "8")\n yield int(x + "9")\n else:\n yield int(x + str(min_x - 1))\n yield int(x + str(min_x)\n yield int(x + str(min_x + 1)))\n\nK = int(input())\nans = 1\nfor i in range(K):\n if i == K - 1:\n ans = heapq.heappop(l)\n break\n for y in f(heapq.heappop(l)):\n heapq.push(l, y)\nprint(ans)', 'import heapq\nl = [1, 2, 3, 4, 5, 6, 7, 8, 9]\nheapq.heapify(l)\n\ndef f(x):\n \n min_x = int(list(str(x))[-1])\n if min_x == 0:\n yield int(x + "0")\n yield int(x + "1")\n elif min_x == 9:\n yield int(x + "8")\n yield int(x + "9")\n else:\n yield int(x + str(min_x - 1))\n yield int(x + str(min_x))\n yield int(x + str(min_x + 1))\n\nK = int(input())\nans = 1\nfor i in range(K):\n if i == K - 1:\n ans = heapq.heappop(l)\n break\n for y in f(heapq.heappop(l)):\n heapq.push(l, y)\nprint(ans)', 'import heapq\nl = [1, 2, 3, 4, 5, 6, 7, 8, 9]\nheapq.heapify(l)\n\ndef f(x):\n \n min_x = int(list(str(x))[-1])\n x = str(x)\n if min_x == 0:\n yield int(x + "0")\n yield int(x + "1")\n elif min_x == 9:\n yield int(x + "8")\n yield int(x + "9")\n else:\n yield int(x + str(min_x - 1))\n yield int(x + str(min_x))\n yield int(x + str(min_x + 1))\n\nK = int(input())\nans = 1\nfor i in range(K):\n if i == K - 1:\n ans = heapq.heappop(l)\n break\n for y in f(heapq.heappop(l)):\n heapq.heappush(l, y)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s166555582', 's339277500', 's029040658']
[3064.0, 3064.0, 10780.0]
[17.0, 18.0, 435.0]
[597, 597, 616]
p02720
u531579566
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['def dp(i, j, memo):\n key = "{}.{}".format(i, j)\n\n if i == 1:\n memo[key] = 1\n return memo[key]\n\n if key in memo:\n return memo[key]\n\n if j == 0:\n memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)\n return memo[key]\n\n if j == 9:\n memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)\n return memo[key]\n\n memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)\n return memo[key]\n\n\nk = int(input())\nmemo = {"1.0": 0}\n\nnum = 0\n\ni = 1\nj = 0\n\nwhile(num < k):\n j += 1\n j %= 10\n if j == 0:\n i += 1\n else:\n num += dp(i, j, memo)\n\np = k - num + dp(i, j, memo)\nans = [j]\nprint(i, j)\nfor l in range(1, i):\n n = 0\n x = max(-1, ans[-1] - 2)\n while n < p and x < 10:\n x += 1\n n += dp(i-l, x, memo)\n ans.append(x)\n p = p - n + dp(i-l, x, memo)\n\nprint("".join(map(str, ans)))\n', 'def dp(i, j, memo):\n key = "{}.{}".format(i, j)\n\n if i == 1:\n memo[key] = 1\n return memo[key]\n\n if key in memo:\n return memo[key]\n\n if j == 0:\n memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)\n return memo[key]\n\n if j == 9:\n memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)\n return memo[key]\n\n memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)\n return memo[key]\n\n\nk = int(input())\nmemo = {"1.0": 0}\n\nnum = 0\n\ni = 1\nj = 0\n\nwhile(num < k):\n j += 1\n j %= 10\n if j == 0:\n i += 1\n else:\n num += dp(i, j, memo)\n\np = k - num + dp(i, j, memo)\nans = [j]\nfor l in range(1, i):\n n = 0\n x = max(-1, ans[-1] - 2)\n while n < p and x < 10:\n x += 1\n n += dp(i-l, x, memo)\n ans.append(x)\n p = p - n + dp(i-l, x, memo)\n\nprint("".join(map(str, ans)))\n']
['Wrong Answer', 'Accepted']
['s118650714', 's279665679']
[3064.0, 3192.0]
[17.0, 17.0]
[892, 880]
p02720
u552357043
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['#!/usr/bin/env python3\nans = [0] * 10\nans[1] = \'1\'\nfor i in range(2, 10):\n ans[i] = str(i)\nalpha = "0123456789"\ndef dfs(s):\n if len(s) == N:\n ans.append(s)\n if len(ans) >= 100001:\n return\n else:\n for c in range(int(s[-1])-1,int(s[-1])+2):\n if c >= 0:\n dfs(s+str(c))\n if c == \'9\':\n break\nK = int(input())\nN = 2\nwhile len(ans) < 100001:\n for i in range(1, 10):\n dfs(str(i))\n if len(ans) >= 100001:\n break\n N+=1\n\nprint(ans[K])', '#!/usr/bin/env python3\nans = [0] * 10\nans[1] = \'1\'\nfor i in range(2, 10):\n ans[i] = str(i)\nalpha = "0123456789"\ndef dfs(s):\n if len(s) == N:\n ans.append(s)\n if len(ans) >= 100001:\n return\n else:\n for c in (int(s[-1])-1,int(s[-1])+2):\n if c >= 0:\n dfs(s+str(c))\n if c == \'9\':\n break\nK = int(input())\nN = 2\nwhile len(ans) < 100001:\n for i in range(1, 10):\n dfs(str(i))\n if len(ans) >= 100001:\n break\n N+=1\n\nprint(ans[K])', '#!/usr/bin/env python3\nans = [0] * 10\nans[1] = \'1\'\nfor i in range(2, 10):\n ans[i] = str(i)\nalpha = "0123456789"\ndef dfs(s):\n if len(s) == N:\n ans.append(s)\n if len(ans) >= 100001:\n return\n else:\n for c in range(int(s[-1])-1,int(s[-1])+2):\n if c >= 0:\n dfs(s+str(c))\n if c == 9:\n break\nK = int(input())\nN = 2\nwhile len(ans) < 100001:\n for i in range(1, 10):\n dfs(str(i))\n if len(ans) >= 100001:\n break\n N+=1\n\nprint(ans[K])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s784835642', 's786848066', 's024622509']
[4488.0, 4552.0, 11052.0]
[78.0, 76.0, 157.0]
[547, 542, 545]
p02720
u567430603
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\nK = int(input())\nd = deque(range(1, 10))\nfor i in range(K):\n x = d.popleft()\n if x % 10 != 0:\n d.append(10*x-1)\n d.append(10*x)\n if x % 10 != 9:\n d.append(10*x+1)\nprint(x)', 'from collections import deque\nK = int(input())\nd = deque(range(1, 10))\nfor i in range(K):\n x = d.popleft()\n if x % 10 != 0:\n d.append(10*x+(x % 10)-1)\n d.append(10*x+(x % 10))\n if x % 10 != 9:\n d.append(10*x+(x % 10)+1)\nprint(x)']
['Wrong Answer', 'Accepted']
['s896427334', 's212414917']
[9404.0, 11908.0]
[89.0, 123.0]
[227, 254]
p02720
u572138437
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['cur = []\n\ndef recur(n):\n if n > 10 ** 18:\n return\n cur.append(n)\n for i in range(10):\n if abs(n % 10 - i) <= 1:\n recur(10 * n + i)\n\nfor i in range(1, 10):\n recur(i)\ncur.sort()\nn = int(input())\nprint((cur[n - 1]))', 'cur = []\n\ndef recur(n):\n if n > 10 ** 10:\n return\n cur.append(n)\n for i in range(10):\n if abs(n % 10 - i) <= 1:\n recur(10 * n + i)\n\nfor i in range(1, 10):\n recur(i)\ncur.sort()\nn = int(input())\nprint((cur[n - 1]))']
['Time Limit Exceeded', 'Accepted']
['s968057386', 's103057122']
[54372.0, 12776.0]
[2110.0, 462.0]
[249, 249]
p02720
u580697892
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['# coding: utf-8\nfrom collections import deque\nK = int(input())\nqueue = [str(i) for i in range(1, 10)]\n\nqueue = deque(queue)\nL = []\ncnt = 0\nwhile cnt <= K:\n v = queue.popleft()\n # L.push(int(v))\n L.append(int(v))\n if v[-1] == "0":\n # print("v =", v)\n queue.append(v + v[-1])\n queue.append(v+"1")\n \n elif v[-1] == "9":\n # print("9", v)\n queue.append(v + "8")\n queue.append(v + v[-1])\n else:\n # print("else", v)\n t = int(v[-1])\n queue.append(v+str(t-1))\n queue.append(v + v[-1])\n queue.append(v+str(t+1))\n cnt += 1\nprint(v)', '# coding: utf-8\nfrom collections import deque\nK = int(input())\nqueue = [str(i) for i in range(1, 10)]\n\nqueue = deque(queue)\nL = []\ncnt = 0\nwhile cnt < K:\n v = queue.popleft()\n # L.push(int(v))\n L.append(int(v))\n if v[-1] == "0":\n # print("v =", v)\n queue.append(v + v[-1])\n queue.append(v+"1")\n \n elif v[-1] == "9":\n # print("9", v)\n queue.append(v + "8")\n queue.append(v + v[-1])\n else:\n # print("else", v)\n t = int(v[-1])\n queue.append(v+str(t-1))\n queue.append(v + v[-1])\n queue.append(v+str(t+1))\n cnt += 1\nprint(v)']
['Wrong Answer', 'Accepted']
['s001278380', 's416056505']
[20872.0, 20872.0]
[216.0, 223.0]
[639, 638]
p02720
u585348179
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['k=int(input())\n \nfrom collections import deque\nq = deque(range(1, 10))\n\nfor i in range(k-1):\n d = q.popleft()\n if d % 10 != 0:\n q.append(10*d-1)\n q.append(10*d)\n if d % 10 != 9:\n q.append(10*d+1)\n \nprint(q.popleft())', 'k=int(input())\n\nfrom collections import deque\nq = deque(range(1,10))\n\nfor i in range(k-1):\n d = q.popleft()\n #10\n if d % 10 != 0:\n q.append(10 * d + d % 10 - 1)\n #11\n q.append(10 * d + d % 10)\n #12\n if d % 10 != 9:\n q.append(10 * d + d % 10 + 1)\nprint(q.popleft())\n\n\n']
['Wrong Answer', 'Accepted']
['s912107775', 's416865750']
[9404.0, 11912.0]
[87.0, 126.0]
[245, 302]
p02720
u594803920
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["\nimport sys\n\nsys.setrecursionlimit(10**9)\n\ndef runrun(n):\n if n == 1:\n return [['1','2','3','4','5','6','7','8','9']]\n else:\n li = runrun(n-1)\n li2 = []\n for i in range(len(li[n-2])):\n p = int(li[n-2][i][-1])\n if p == 0:\n li2.append(li[n-2][i]+'0')\n li2.append(li[n-2][i]+'1')\n elif p == 9:\n li2.append(li[n-2][i]+str(8))\n li2.append(li[n-2][i]+'9')\n else:\n li2.append(li[n-2][i]+str(p-1))\n li2.append(li[n-2][i]+str(p))\n li2.append(li[n-2][i]+str(p+1))\n li2 =[li2]\n li.extend(li2)\n return li\n \n\n\nx = int(input())\nt = True\nk=1\nb = 0\nwhile t:\n a = runrun(k)\n b = 0\n \n for i in range(len(a)):\n b+=(len(a[i]))\n \n if x <= b:\n t = False\n if k == 1:\n print(x)\n else:\n tmp = runrun(k-1)\n c = 0\n\n for i in range(len(tmp)):\n c += (len(tmp[i]))\n s = a[k-1][x-c-1]\n print(int(s))\n else:\n k += 1\n print(b)", "\nimport sys\n\nsys.setrecursionlimit(10**9)\n\nfrom functools import lru_cache\n@lru_cache(maxsize=None)\n\ndef runrun(n):\n if n == 1:\n return [['1','2','3','4','5','6','7','8','9']]\n else:\n li = runrun(n-1)\n li2 = []\n for i in range(len(li[n-2])):\n p = int(li[n-2][i][-1])\n if p == 0:\n li2.append(li[n-2][i]+'0')\n li2.append(li[n-2][i]+'1')\n elif p == 9:\n li2.append(li[n-2][i]+str(8))\n li2.append(li[n-2][i]+'9')\n else:\n li2.append(li[n-2][i]+str(p-1))\n li2.append(li[n-2][i]+str(p))\n li2.append(li[n-2][i]+str(p+1))\n li2 =[li2]\n li.extend(li2)\n return li\n \n\n\nx = int(input())\nt = True\nk=1\nb = 0\nwhile t:\n a = runrun(k)\n b = 0\n \n for i in range(len(a)):\n b+=(len(a[i]))\n \n if x <= b:\n t = False\n if k == 1:\n print(x)\n else:\n tmp = runrun(k-1)\n c = 0\n\n for i in range(len(tmp)):\n c += (len(tmp[i]))\n s = a[k-1][x-c-1]\n print(int(s))\n else:\n k += 1\n"]
['Wrong Answer', 'Accepted']
['s894502024', 's523206277']
[22064.0, 17820.0]
[213.0, 128.0]
[1374, 1416]
p02720
u595353654
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['# -*- coding: utf-8 -*-\nfrom sys import stdin\nfrom operator import itemgetter\nimport math\n\n\ndef keta(kazu):\n kazu_str = str(kazu)\n kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]\n return kazu_list\n\nK = int(stdin.readline().rstrip())\na = list(range(1,10))\nb = []\nattack = 100000\nwhile attack > 0:\n go = a.pop(0)\n ue = go*10\n shimo = go%10\n b.append(go)\n if shimo == 0:\n a += (ue,ue+1)\n elif shimo == 9:\n a += (ue+shimo-1,ue+shimo)\n else:\n a += (ue+shimo-1,ue+shimo,ue+shimo+1)\n attack -= 1\n\nprint(b[K-1])', '# -*- coding: utf-8 -*-\nfrom sys import stdin\nfrom operator import itemgetter\nimport math\n\n\ndef keta(kazu):\n kazu_str = str(kazu)\n kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]\n return kazu_list\n\nK = int(stdin.readline().rstrip())\na = list(range(1,10))\nb = []\n\nfor i in range(100000):\n go = a.pop(0)\n ue = go*10\n shimo = go%10\n b.append(go)\n if shimo == 0:\n a += (ue,ue+1)\n elif shimo == 9:\n a += (ue+shimo-1,ue+shimo)\n else:\n a += (ue+shimo-1,ue+shimo,ue+shimo+1)\n\nprint(b[K-1])', '# -*- coding: utf-8 -*-\nfrom sys import stdin\nfrom operator import itemgetter\nimport math\n\n\ndef keta(kazu):\n kazu_str = str(kazu)\n kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]\n return kazu_list\n\nK = int(stdin.readline().rstrip())\na = list(range(1,10))\nb = []\nattack = 100000\nwhile attack > 0:\n go = a.pop(0)\n ue = go*10\n shimo = go%10\n b.append(go)\n if shimo == 0:\n a.append(ue)\n a.append(ue+1)\n elif shimo == 9:\n a.append(ue+shimo-1)\n a.append(ue+shimo)\n else:\n a.append(ue+shimo-1)\n a.append(ue+shimo)\n a.append(ue+shimo+1)\n attack -= 1\n\nprint(b[K-1])', '# -*- coding: utf-8 -*-\nfrom sys import stdin\nfrom operator import itemgetter\nfrom collections import deque\nimport math\n\n\nK = int(stdin.readline().rstrip())\na = deque(range(1,10))\nans_list = deque()\nattack = 100000\nwhile attack > 0:\n ans = a.popleft()\n ue = ans*10\n shimo = ans%10\n ans_list.append(ans)\n if shimo == 0:\n a.append(ue)\n a.append(ue+1)\n elif shimo == 9:\n a.append(ue+shimo-1)\n a.append(ue+shimo)\n else:\n a.append(ue+shimo-1)\n a.append(ue+shimo)\n a.append(ue+shimo+1)\n attack -= 1\n\nprint(ans_list[K-1])']
['Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted']
['s603525616', 's885631990', 's888500223', 's020158393']
[13660.0, 13688.0, 13612.0, 16240.0]
[2104.0, 2104.0, 2105.0, 134.0]
[601, 576, 682, 615]
p02720
u597374218
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K=int(input())\nnumber=[]\nfor i in range(3234566668):\n k=str(i)\n if all([abs(int(k[j])-int(k[j-1]))<=1 for j in range(1,len(k))]):\n number.append(k)\nprint(number[K])', 'from collections import deque\nK=int(input())\nqueue=deque(list(range(1,10)))\nfor i in range(K):\n k=queue.popleft()\n mod=k%10\n for diff in range(mod-1,mod+2):\n if diff<0 or 9<diff:\n continue\n queue.append(10*k+diff)\nprint(k)']
['Time Limit Exceeded', 'Accepted']
['s534398533', 's014076942']
[9196.0, 19664.0]
[2206.0, 134.0]
[177, 256]
p02720
u597455618
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['import collections\n\ndef main():\n k = int(input())\n Q = collections.deque([int(i) for i in range(1, 10)])\n for i in range(k):\n x = Q.popleft()\n if i + len(Q) < k:\n if x%10:\n Q.append(10*x + x%10 - 1)\n Q.append(10*x + x%10)\n if x%10 != 9:\n Q.append(10*x + x%10 + 1)\n print(Q)\n print(x)\n\nif __name__ == "__main__":\n main()', 'import collections\n\ndef main():\n k = int(input())\n Q = collections.deque([int(i) for i in range(1, 10)])\n chk = False\n for i in range(k):\n x = Q.popleft()\n if i + len(Q) > k:\n chk = True\n if chk:\n continue\n else:\n if x%10:\n Q.append(10*x + x%10 - 1)\n Q.append(10*x + x%10)\n if x%10 != 9:\n Q.append(10*x + x%10 + 1)\n print(x)\n\nif __name__ == "__main__":\n main()']
['Runtime Error', 'Accepted']
['s591562525', 's945862680']
[140492.0, 12108.0]
[1347.0, 61.0]
[418, 491]
p02720
u601575292
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['for i in range(N):\n\tif (A[i]*4*M) >= vote_sum:\n\t\tcnt += 1\n\tif cnt == M:\n\t\tprint(y)\n\t\tbreak\n\t\t\nif C < M:\n\tprint(n)', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\nvote_sum = sum(A)\ncnt = 0\ny = "Yes"\nn = "No"\n\nfor i in range(N):\n\tif (A[i]*4*M) >= vote_sum:\n\t\tcnt += 1\n\tif cnt == M:\n\t\tprint(y)\n\t\tbreak\n\t\t\nif C < M:\n\tprint(n)', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\nvote_sum = sum(A)\ncnt = 0\ny = "Yes"\nn = "No"\n\nfor i in range(N):\n\tif (A[i]*4*M) >= vote_sum:\n\t\tcnt += 1\n\tif cnt == M:\n\t\tprint(y)\n\t\t\nif C < M:\n\tprint(n)', 'from collections import deque\nK = int(input())\n\nq = deque([i for i in range(1, 10)])\n\nfor i in range(K):\n x = q.popleft()\n amari = x%10\n if amari == 0:\n l, m = 10*x, 10*x+1\n q.append(l)\n q.append(m)\n elif amari == 1:\n l, m, r = x*10, x*10+1, x*10+2\n q.append(l)\n q.append(m)\n q.append(r)\n elif amari == 9:\n l, m = 10*x+8, 10*x+9\n q.append(l)\n q.append(m)\n else:\n l, m, r = 10*x+(amari-1), 10*x+(amari), 10*x+(amari+1)\n q.append(l)\n q.append(m)\n q.append(r)\n\nprint(x)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s158246489', 's200935908', 's628623719', 's117424691']
[2940.0, 3064.0, 3064.0, 12916.0]
[17.0, 17.0, 17.0, 121.0]
[113, 228, 220, 583]
p02720
u619144316
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K = int(input())\ncount =0 \nj =0 \nwhile True:\n j+=1\n t = [int(i) for i in list(str(j))]\n a = len(t)\n for i,v in enumerate(t):\n if i < a-1:\n if abs(t[i] - t[i+1]) > 1:\n break\n count += 1\n if count ==K:\n print(j)\n exit()', 'import queue\n\nK = int(input())\n\nq = queue.Queue()\nans = []\ncnt = 0\nfor i in range(1,10):\n q.put(i)\n ans.append(i)\n cnt += 1\n\nwhile cnt <= 10**5:\n n = q.get()\n m = n %10\n if m == 0:\n q.put(n*10+0)\n q.put(n*10+1)\n ans.append(n*10)\n ans.append(n*10+1)\n cnt += 1\n elif m == 9:\n q.put(n*10+8)\n q.put(n*10+9)\n ans.append(n*10+8)\n ans.append(n*10+9)\n cnt += 2\n else:\n q.put(n*10+m-1)\n q.put(n*10+m)\n q.put(n*10+m+1)\n ans.append(n*10+m-1)\n ans.append(n*10+m)\n ans.append(n*10+m+1)\n cnt += 3\n\nprint(ans[K-1])']
['Wrong Answer', 'Accepted']
['s751020015', 's321617618']
[3064.0, 10948.0]
[307.0, 424.0]
[282, 642]
p02720
u621345513
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['from collections import deque\n\nk = 9 #+ (9*3-1)\ncount = 0\nq = deque(range(1,10))\n\nwhile count < k:\n l = q.popleft()\n resid = l % 10\n if resid != 0: q.append(l*10 + resid - 1)\n\n q.append(l*10 + resid)\n \n if resid != 9: q.append(l*10 + resid + 1)\n \n count += 1\n\nprint(l)', 'k = int(input())\n\ncount = 0\nq = deque(range(1,10))\n\nwhile count < k:\n l = q.popleft()\n resid = l % 10\n if resid != 0: q.append(l*10 + resid - 1)\n\n q.append(l*10 + resid)\n \n if resid != 9: q.append(l*10 + resid + 1)\n \n count += 1\n\nprint(q[k-1])', 'from collections import deque\n\nk = 100\ncount = 0\nq = deque(range(1,10))\n\nwhile count < k:\n l = q.popleft()\n resid = l % 10\n if resid != 0: q.append(l*10 + resid - 1)\n\n q.append(l*10 + resid)\n \n if resid != 9: q.append(l*10 + resid + 1)\n \n count += 1\n\nprint(q[k-1])', "K = int(input())\n\nfrom itertools import product\nd = {}\nnum_list = []\nfor i in range(10):\n nums = set([min((i-1)%10, i), i, max((i+1)%10, i)])\n\n nums = [str(el) for el in nums]\n d[i] = list(product([str(i)], list(nums)))\n d[i] = [int(''.join(el)) for el in d[i]]\n d[i] = ['{:02}'.format(el) for el in d[i]]\n \n num_list.extend(d[i])\nnum_list = sorted(num_list)\ndd = [None, None, d, \n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(1,10)},\n {i:[] for i in range(10)}]\n\ndef gen_2ll():\n count = 0\n ret = 0\n while int(ret)!=99:\n if int(ret)< 9 :\n ret += 1\n count += 1\n yield ret\n else:\n for i in range(1,10):\n for ret in d[i]:\n count += 1\n yield ret\n\nll2_list = list(gen_2ll())\n \ndef get_digit_top_list(num_digit, top_num):\n ret = dd[num_digit][top_num]\n if ret:\n return ret\n\n second_nums = sorted(set([min((top_num-1)%10, top_num), top_num, max((top_num+1)%10, top_num)])) \n for second_num in second_nums:\n rem_nums = get_digit_top_list(num_digit-1, int(second_num))\n for rem_num in rem_nums:\n ll = str(top_num) + rem_num\n ret.append(ll)\n dd[num_digit][top_num] = ret\n\n \n return ret\n\ndef get_ll(K):\n\ndef get_kth_ll(K):\n if K<=len(ll2_list):\n print(ll2_list[K-1])\n else:\n K -= len(ll2_list)\n for num_digit in range(3,100):\n for top_num in range(1,10):\n _ll_list = get_digit_top_list(num_digit, top_num)\n if K-len(_ll_list)<0:\n print(sorted([int(el) for el in _ll_list])[K])\n else:\n K -= len(_ll_list)\nget_kth_ll(K)\n ", 'from collections import deque\n\nk = int(input())\ncount = 0\nq = deque(range(1,10))\n\nwhile count < k:\n l = q.popleft()\n resid = l % 10\n if resid != 0: q.append(l*10 + resid - 1)\n\n q.append(l*10 + resid)\n \n if resid != 9: q.append(l*10 + resid + 1)\n \n count += 1\n\nprint(l)']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s609755436', 's703207095', 's782874823', 's900946027', 's223003384']
[3316.0, 3060.0, 3316.0, 3192.0, 11956.0]
[21.0, 17.0, 20.0, 17.0, 116.0]
[293, 267, 288, 2410, 292]
p02720
u634282234
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K=int(input())\nnums=[i for i in range(1,10)]\nfor i in range(K):\n a=nums.pop(0)\n if a%10!=0:\n nums.append(a*10 + %10 - 1)\n \n nums.append(a*10 + a%10)\n \n if a%10!=9:\n nums.append(a*10 + a%10 + 1)\n\nprint(a)\n', 'K=int(input())\nnums=[i for i in range(1,10)]\nfor i in range(K):\n a=nums.pop(0)\n if a%10!=0:\n nums.append(a*10 + %10 - 1)\n \n nums.append(a*10 + a%10)\n \n if a%10!=9:\n nums.append(a*10 + a%10 + 1)\n\nprint(a)\n', 'K=int(input())\nnums=[i for i in range(1,10)]\nfor i in range(K):\n a=nums.pop(0)\n if a%10!=0:\n nums.append(a*10 + a%10 - 1)\n \n nums.append(a*10 + a%10)\n \n if a%10!=9:\n nums.append(a*10 + a%10 + 1)\n\nprint(a)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s089220090', 's504977387', 's353429554']
[9020.0, 9040.0, 18592.0]
[24.0, 24.0, 1947.0]
[236, 236, 236]
p02720
u640922335
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
['K=int(input())\n\nfrom collections import deque\nnum=deque()\nfor i in range(1,10):\n num.append(i)\n\nfor j in range(K):\n l=num.popleft()\n if ans%10 !=0:\n num.append(l*10+(l%10-1))\n num.append(l*10)\n if ans%10 != 9:\n num.append(l*10+(l%10+1))\n\nprint(l)\n \n ', 'K=int(input())\n\nfrom collections import deque\nnum=deque()\nfor i in range(1,10):\n num.append(i)\n\nfor j in range(K):\n l=num.popleft()\n if l%10 !=0:\n num.append(l*10+(l%10-1))\n num.append(l*10+(l %10))\n if l%10 != 9:\n num.append(l*10+(l%10+1))\n\nprint(l)']
['Runtime Error', 'Accepted']
['s051575229', 's651175490']
[3316.0, 12384.0]
[20.0, 122.0]
[263, 261]
p02720
u644516473
2,000
1,048,576
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is. You are given a positive integer K. Find the K-th smallest lunlun number.
["import sys\nfrom functools import lru_cache\nsys.setrecursionlimit(10**9)\nk = int(input())\nlunlun = []\n\n\n@lru_cache(maxsize=100000000)\ndef func(i):\n if int(i) > 3234566667 + 10 or len(i) > 6:\n return\n lunlun.append(int(i))\n f = int(i[0])\n b = int(i[-1])\n if f != 0:\n func(f'{f-1}{i}')\n if f != 9:\n func(f'{f+1}{i}')\n func(f'{f}{i}')\n if b != 0:\n func(f'{i}{b-1}')\n if b != 9:\n func(f'{i}{b+1}')\n func(f'i}{b}')\n\n\nfor i in range(10):\n func(str(i))\nlunlun = sorted(set(lunlun))\nprint(len(lunlun))\nprint(lunlun[k])\n", 'from collections import deque\n\nk = int(input())\nq = deque(range(1, 10))\nfor _ in range(k):\n x = q.popleft()\n r = x % 10\n if r != 0:\n q.append(10*x + (r - 1))\n q.append(10*x+r)\n if r != 9:\n q.append(10*x + (r + 1))\nprint(x)\n']
['Runtime Error', 'Accepted']
['s415994996', 's519740115']
[2940.0, 12404.0]
[17.0, 108.0]
[578, 252]