TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
#K = int(input())
N,K = map(int,input().split())
#N = int(input())
#A = list(map(int,input().split()))
flag=True
c=N
if N%K==0:
    print(0)
else:
    l=N//K
    while flag==True:

        N=abs(l-K)
        if c <= N:
            flag=False
        else:
            c=N
print(c)


#K = int(input())
N,K = map(int,input().split())
#N = int(input())
#A = list(map(int,input().split()))
flag=True
c=N
if N%K==0:
    print(0)
    exit()
else:
    l=N//K
    N-=l*K
    while flag==True:

        N=abs(N-K)
        if c <= N:
            flag=False
        else:
            c=N
print(c)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,k = map(int,input().split())
if(k==1):
  print(0)
else:
  while(len(n)>1):
    n = n//k
  t = n//k
  for i in range(t):
    n = abs(n-k)
  if(n < abs(k-n)):
    print(n)
  else:
    print(abs(k-n))

n,k = map(int,input().split())
if(k==1):
  print(0)
else:
  t = n%k
  if(n < abs(k-n)):
    print(n)
  else:
    print(abs(k-n))
 

n,k = map(int,input().split())
t = n%k
if(n < abs(k-n)):
  print(n)
else:
  print(abs(k-n))

N, K = map(int,input().split())
t = N%K
if (K - t) >= t:
    print(t)
else:
    print(K - t)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n % k
  while ans > abs(n-k):
    n = abs(n - k)
    ans = min(n, ans)
  print(ans)

n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n % k
  #print(ans)
  while ans > k//2:
    n = abs(ans - k)
    ans = min(n, ans)
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,k = map(int,input().split())
print(min(n%k,k-n%k)

n,k = map(int,input().split())
print(min(n%k,k-n%k))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,k=map(int,input().split())
n=n%k
print(n)

k=int(input())

a=[]
i=1
d=0
while True:
    if len(str(i))==1:
        a.append(i)
    elif len(str(i))==2:
        I=str(i)
        c=abs(int(I[0])-int(I[1]))
        if c<=1:
            a.append(i)   
            
    elif len(str(i))==3:
        I=str(i)
        for j in range(2):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==2:
            a.append(i)
        d=0
        
    elif len(str(i))==4:
        I=str(i)
        for j in range(3):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==3:
            a.append(i) 
        d=0
        
    elif len(str(i))==5:
        I=str(i)
        for j in range(4):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==4:
            a.append(i)   
        d=0
        
    elif len(str(i))==6:
        I=str(i)
        for j in range(5):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==5:
            a.append(i)
        d=0
    
    elif len(str(i))==7:
        I=str(i)
        for j in range(6):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==6:
            a.append(i)
            
        d=0    
        
    elif len(str(i))==8:
        I=str(i)
        for j in range(7):
            c=abs(int(I[j])-int(I[j+1]))
            if c<=1:
                d=d+1
        if d==7:
            a.append(i)
            
        d=0    
        
    i=i+1
    if i==10000000:
        break

print(a[k-1])

n,k=map(int,input().split())
n=n%k
a=min(n,abs(n-k))
print(a)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
if n<=10 : 
  print(n)
  exit()
  
ans=[0 for i in range(10**5+21)]
Q=[0,1,2,3]
def li(x):
  if x==0 : return [0,1]
  if x==9 : return [8,9]
  return [x-1,x,x+1]

now=0
for q in Q:
  W=[i for i in range(10)] if q==0 else li(q)
  for w in W:
    E=[i for i in range(10)] if [q,w]==[0,0] else li(w)
    for e in E:
      R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)
      for r in R:
        T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)
        for t in T:
          Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)
          for y in Y:
            U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)
            for u in U:
              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)
              for i in I:
                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)
                for o in O:
                  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)
                  for p in P:
                    
                    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
                    
                    if now>=10**5+2 : break
                    now+=1

ans=list(set(ans))
ans.sort()
print(ans[n])



n=int(input())
ans=[0 for i in range(10**5+21)]
Q=[0,1,2,3]
def li(x):
  if x==0 : return [0,1]
  if x==9 : return [8,9]
  return [x-1,x,x+1]

now=0
for q in Q:
  W=[i for i in range(10)] if q==0 else li(q)
  for w in W:
    E=[i for i in range(10)] if [q,w]==[0,0] else li(w)
    for e in E:
      R=[i for i in range(10)] if [q,w,e]==[0,0,0] else li(e)
      for r in R:
        T=[i for i in range(10)] if [q,w,r,e]==[0,0,0,0] else li(r)
        for t in T:
          Y=[i for i in range(10)] if [q,w,e,r,t]==[0,0,0,0,0] else li(t)
          for y in Y:
            U=[i for i in range(10)] if [q,w,e,r,t,y]==[0,0,0,0,0,0] else li(y)
            for u in U:
              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)
              for i in I:
                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)
                for o in O:
                  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)
                  for p in P:
                    
                    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
                    
                    if now>=10**5+2 : break
                    now+=1


print(ans[n])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    seen.append(value)
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)

# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import itertools
k=int(input())
l=[[1,2,3,4,5,6,7,8,9]]
for _ in range(10):
  a=[]
  for i in range(len(l[-1])):
    L=l[-1][i]
    if L%10==9:
      a.append(L*10+8)
      a.append(L*10+9)
    elif L%10==0:
      a.append(L*10+0)
      a.append(L*10+1)
    else:
      a.append(L*10+L%10-1)
      a.append(L*10+L%10)
      a.append(L*10+L%10+1)
    l.append(a)
print(sorted(set(list(itertools.chain.from_iterable(l))))[k-1])

from collections import deque
k=int(input())
l=deque([1,2,3,4,5,6,7,8,9])
for i in range(k-1):
  d=l.popleft()
  a=d%10
  if a!=0:
    l.append(d*10+a-1)
  l.append(d*10+a)
  if a!=9:
    l.append(d*10+a+1)
print(l.popleft())

Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
k = int(input())
def dfs(s):
  if len(s)<10:
    for i in range(-1, 2, 1):
      s+str(min(9, max(0, int(s[-1])+i)))
      return dfs(s)
  else:
    return s
S = []
for i in range(10):
  S.append(dfs(str(i)))
  

import sys
sys.setrecursionlimit(10**6)

k = int(input())
S = []
def dfs(s):
  if len(s)<10:
    for i in range(-1, 2, 1):
      a = str(min(9, max(0, int(s[0])+i)))+s
      S.append(a)
      dfs(a)

for i in range(10):
  S.append(i)
  dfs(str(i))
S = sorted(set([int(s) for s in S]))
print(S[k])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
import math
def cmb(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
e={}
dd=0
for i,j in d.items():
    dd+=combination(j, 2)
    e[i]=combination(j-1, 1)

for i in a:
    print(dd-e[i])
  


k=int(input())
if k<=9:
    print(k)
    exit()
a=[1,2,3,4,5,6,7,8,9]
cnt=9
while True:
    q=[]
    for i in a:
       for j in range(10):
            if abs(int(str(i)[-1])-j)<=1:
                cnt+=1
                if cnt==k:
                    print(int(str(i)+str(j)))
                    exit()
                q.append(int(str(i)+str(j)))         
    a=list(sorted(set(q)))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
K = int(input())

min_r = 0
max_r = 12

def count(idx, n):
    if idx==0:
        return 1
    if n==0:
        return count(idx-1, 1)+count(idx-1, 0)
    elif n==9:
        return count(idx-1, 9)+count(idx-1, 8)
    else:
        return count(idx-1, n-1)+count(idx-1, n)+count(idx-1, n+1)

lists = []
def count_2(idx, n, list_b):
    lis = list_b[:]
    lis.append(str(n))
    if idx==0:
        lists.append(int(''.join(lis)))
        return 1
    if n==0:
        count_2(idx-1, 1, lis)
        count_2(idx-1, 0, lis)
    elif n==9:
        count_2(idx-1, 9, lis)
        count_2(idx-1, 8, lis)
    else:
        count_2(idx-1, n-1, lis)
        count_2(idx-1, n, lis)
        count_2(idx-1, n+1, lis)

d = 0
now = 0
while 1:
    p = sum([count(d, i) for i in range(1, 10)])
    now += p
    if now>K:
        now -= p
        break
    d += 1

sump = 0
for i in range(1, 10):
    sump_old = sump
    sump += count(d, i)
    if sump+now>K:
        break
count_2(d, i, [])
print(lists[K-now-sump_old+1])

K = int(input())
from collections import deque

queue = deque()
for i in range(1, 10):
    queue.appendleft(i)

for _ in range(K-1):
    p = queue.pop()
    if p%10!=0:
        queue.appendleft(p*10+p%10-1)
    queue.appendleft(p*10+p%10)
    if p%10!=9:
        queue.appendleft(p*10+p%10+1)

print(queue.pop())


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import headq

heap=[]
N = input()
for i in range(10):
  heapq.heappush(heap,i)
print(heap)


import heapq
 
heap=[]
N = int(input())
for i in range(1,10):
  heapq.heappush(heap,i)
for i in range(N):
  x = heapq.heappop(heap)
  if x%10!=0:
    heapq.heappush(heap,10*x+(x%10)-1)
  heapq.heappush(heap,10*x+(x%10))
  if x%10!=9:
    heapq.heappush(heap,10*x+(x%10)+1)
  
print(x)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
k = int(input())
a[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(k):
    if a[i] % 10 != 0:
        a.append(10*a[i] + a[i] % 10 - 1)
    a.append(10*a[i] + a[i] % 10)
    if a[i] % 10 != 9:
        a.append(10*a[i] + a[i] % 10 + 1)

print(a[k - 1])


k = int(input())
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(k):
    if a[i] % 10 != 0:
        a.append(10*a[i] + a[i] % 10 - 1)
    a.append(10*a[i] + a[i] % 10)
    if a[i] % 10 != 9:
        a.append(10*a[i] + a[i] % 10 + 1)

print(a[k - 1])


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
k = int(input())
l = ['1','2','3','4','5','6','7','8','9']
lf = ['1','2','3','4','5','6','7','8','9']
sum = 9
while sum < k:
    lff = []
    for i in lf:
        if i[-1] == [0]:
            lff.append(i+'0')
            lff.append(i+'1')
        elif i[-1] == [9]:
            lff.append(i+'8')
            lff.append(i+'9')
        else:
            lff.append(i+str(int(i[-1]-1)))
            lff.append(i+str(int(i[-1])))
            lff.append(i+str(int(i[-1]+1)))
    lf = lff
    l += lff
print(l[k-1])

k = int(input())
l = ['1','2','3','4','5','6','7','8','9']
lf = l.copy()
sum = 9
while sum < k:
    lff = []
    for i in lf:
        if i[-1] == '0':
            lff.append(i+'0')
            lff.append(i+'1')
        elif i[-1] == '9':
            lff.append(i+'8')
            lff.append(i+'9')
        else:
            lff.append(i+str(int(i[-1])-1))
            lff.append(i+str(int(i[-1])))
            lff.append(i+str(int(i[-1])+1))
    lf = lff
    l += lff
    sum += len(lff)
print(int(l[k-1]))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import log10,ceil
def main():
    k = int(input())
    k2 = ceil(k / 10)
    def getlun(n):
        lunluns.append(n)
        ns = str(n)
        print(lunluns)
        if len(ns) > k2:
            pass
        else:
            ns1 = int(ns[0])
            if ns1 != 0:
                l1 = ns[0] + ns
                getlun(int(l1))
            if ns1 > 1:
                l2 = str(ns1 - 1) + ns
                getlun(int(l2))
            if ns1 < 9:
                l3 = str(ns1 + 1) + ns
                getlun(int(l3))
    lunluns = []
    for i1 in range(0, 10):
        getlun(i1)
    lunluns.sort()
    print(lunluns[k])

if __name__ == '__main__':
    main()

import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log
def main():
    k = int(input())
    k2 = int(log(ceil(k / 10), 3)) + 1
    def getlun(n, keta, last):
        lunluns.append(n)
        if keta > k2:
            pass
        else:
            l1 = n * 10 + last
            getlun(l1, keta + 1, last)
            if last > 0:
                l2 = n * 10 + last - 1
                getlun(l2, keta + 1, last - 1)
            if last < 9:
                l3 = n * 10 + last + 1
                getlun(l3, keta + 1, last + 1)
    lunluns = []
    for i1 in range(1, 10):
        getlun(i1, 0, i1)
    lunluns.sort()
    print(lunluns[k-1])

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import product
K = int(input())

ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(''.join(map(str, X)))

ans.sort()
print(ans[K - 1])


from itertools import product
K = int(input())

ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(int(''.join(map(str, X))))

ans.sort()
print(ans[K - 1])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]
import heapq
heapq.heapify(a)
cnt = 18
c = 1
while True:
  if cnt > 10**5:
    break
  for i in a:
    if len(str(i)) == c:
      m = i//10**(c-1)
      if i//10**(c-1) == 1:
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 2
        for j in range(10-c):
          heapq.heappush(a,i+10**c*(10**(j+1)))
          cnt += 1
      elif i//10**(c-1) == 9:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        cnt += 2
      else:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
  c += 1

k = int(input())
#a = set(a)
#a = list(a)
for i in range(k):
  heapq.heappop(a)
print(heapq.heappop(a))

a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]
import heapq
heapq.heapify(a)
cnt = 18
c = 1
while True:
  if cnt > 10**5:
    break
  for i in a:
    if len(str(i)) == c:
      m = i//10**(c-1)
      if i//10**(c-1) == 1:
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 2
        for j in range(10-c):
          heapq.heappush(a,i+10**c*(10**(j+1)))
          cnt += 1
      elif i//10**(c-1) == 9:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        cnt += 2
      else:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
  c += 1

k = int(input())
#a = set(a)
#a = list(a)
for i in range(k-1):
  heapq.heappop(a)
print(heapq.heappop(a))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
k = int(input())

numset = {i for i in range(1,10)}
flag = False
count = len(numset)
if count >= k:
    flag = True
arr = [numset]
index = 0

while not flag:
    beforeset = arr[index]
    tmpset = set()
    for i in beforeset:
        tail = str(i)[-1]
        if tail == "0":
            tmpset.add(int(str(i)+str(0)))
            tmpset.add(int(str(i)+str(1)))
        elif tail == "9":
            tmpset.add(int(str(i)+str(8)))
            tmpset.add(int(str(i)+str(9)))
        else:
            tmpset.add(int(str(i)+str(int(tail))))
            tmpset.add(int(str(i)+str(int(tail)+1)))
            tmpset.add(int(str(i)+str(int(tail)-1)))
    count += len(tmpset)
    if count >= k:
        flag = True
    arr.append(tmpset)
    index += 1
    
totalarr = []
for tmpset in arr:
    totalarr += list(tmpset)
    
totalarr.sort()
print(totalarr[k])

k = int(input())

from collection import deque
queue = deque(range(1,10))
count = 0
while count < k:
  count += 1
  tmp = queue.popleft()
  tail = tmp%10
  if tail != 0:
    queue.append(10*tmp+tail-1)
  queue.append(10*tmp)
  if tail != 9:
    queue.append(10*tmp+tail+1)

print(tmp)

k = int(input())
from collections import deque
queue = deque(range(1,10))
count = 0

while count < k:
  count += 1
  tmp = deque.popleft()
  tail = tmp % 10
  if tail!=0:
    deque.append(tmp*10+tail-1)
  deque.append(tmp*10+tail)
  if tail!=9:
    deque.append(tmp*10+tail+1)
  
print(tmp)

k = int(input())
from collections import deque
queue = deque(range(1,10))
count = 0

while count < k:
  count += 1
  tmp = queue.popleft()
  tail = tmp % 10
  if tail!=0:
    queue.append(tmp*10+tail-1)
  queue.append(tmp*10+tail)
  if tail!=9:
    queue.append(tmp*10+tail+1)
  
print(tmp)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

maxi=0
for r in range(11):
  if z[r]<=K:
    maxi=max(maxi,r)
    
keta=maxi+1

print(x[keta][K-y[maxi-1]])


K=int(input())
x=[[0] for _ in range(11)]
y=[ 0 for _ in range(11)]

x[1]=[1,2,3,4,5,6,7,8,9]
y[1]=9

for i in range(2,11):
  x[i].pop()
  for num in x[i-1]:
    last = num%10
    if last==0:
      x[i].append(10*num)
      x[i].append(10*num+1)
      y[i] +=2
    elif last==9:
      x[i].append(10*num+8)
      x[i].append(10*num+9)
      y[i] +=2
    else:
      x[i].append(10*num+(last-1))
      x[i].append(10*num+last)
      x[i].append(10*num+(last+1))
      y[i] +=3
      
#print(y)
#print(sum(y))

z=[0,y[1]]
for i in range(2,11):
 z.append(z[-1]+y[i])
#print(z)

keta=0
for i,num in enumerate(z):
  if num<=K:
    keta=i+1

s= K-z[keta-1]
#print(s)
print(x[keta][s-1])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import deque

k = int(input())

que = deque([1,2,3,4,5,6,7,8,9])

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  q.append(c * 10 + c % 10)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)

from collections import deque

k = int(input())

que = deque([1,2,3,4,5,6,7,8,9])

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  que.append(x * 10 + x % 10)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    k = int(input())
    hp = list(range(1, 10))
    for i in range(k-1):
        n = hp.pop(0)
        if n % 10 != 0:
            hp.append(n * 10 + n - 1)
        hp.append(n * 10 + n)
        if n % 10 != 9:
            hp.append(n * 10 + n + 1)
    print(hp[0])


def main():
    k = int(input())
    hp = [i for i in range(k+4)]
    r, w = 1, 10
    while w <= k:
        n = hp[r]
        r += 1
        nm = n % 10
        val = n * 10 + nm
        
        if nm != 0:
            hp[w] = val - 1
            w += 1
        hp[w] = val
        w += 1
        if nm != 9:
            hp[w] = val + 1
            w += 1

    print(hp[k])

main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

from collections import deque


def f(x):
  s=str(x) 
  y=int(s[-1]) 
  return s+str(y-1) 


def g(x):
  s=str(x) 
  y=int(s[-1]) 
  return s+str(y) 


def h(x):
  s=str(x) 
  y=int(s[-1]) 
  return s+str(y+1) 


K=int(input())


q=deque()


for i in range(1, 10):
  q.append(i)
  


for i in range(K-1):
  num=q.popleft()　
  if v%10!=0: 
    q.append(f(num))
    
  q.append(g(num))
  
  if v%10!=9: 
    q.append(h(num))
    
print(q.popleft()) 


from collections import deque


def f(x):
  s=str(x) 
  y=int(s[-1]) 
  return int(s+str(y-1)) 


def g(x):
  s=str(x) 
  y=int(s[-1]) 
  return int(s+str(y)) 


def h(x):
  s=str(x) 
  y=int(s[-1]) 
  return int(s+str(y+1)) 


K=int(input())


q=deque()


for i in range(1, 10):
  q.append(i)
  


for i in range(K-1):
  num=q.popleft() 
  if num%10!=0: 
    q.append(f(num))
    
  q.append(g(num))
  
  if num%10!=9: 
    q.append(h(num))
    
print(q.popleft()) 

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main(argv):
    k = int(sys.stdin.readline().rstrip("\n"))
    if k < 10:
        return print(k)
    d = {i: [i] for i in range(10)}

    counter = 9
    n = 1
    while counter < k:
        next_d = {}
        candidates = d[0]
        candidates.extend(d[1])
        next_d[0] = sorted([c for c in set(candidates)])
        for i in range(1, 10):
            candidates = d[i - 1]
            candidates.extend(d[i])
            candidates.extend(d.get(i + 1, []))
            next_d[i] = sorted([i * (10 ** n) + c for c in set(candidates)])
            n_candidates = len(next_d[i])
            if (counter + n_candidates) >= k:
                print(next_d[i][k - counter - 1])
                counter += n_candidates
                break
            counter += n_candidates
        d = next_d
        n += 1
    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))

import sys

def main(argv):
    k = int(sys.stdin.readline().rstrip("\n"))
    if k < 10:
        return print(k)
    d = {i: [i] for i in range(10)}

    counter = 9
    n = 1
    while counter < k:
        next_d = {}
        candidates = d[0]
        candidates.extend(d[1])
        next_d[0] = sorted([c for c in set(candidates)])
        for i in range(1, 10):
            candidates = d[i - 1]
            candidates.extend(d[i])
            candidates.extend(d.get(i + 1, []))
            next_d[i] = sorted([i * (10 ** n) + c for c in set(candidates)])
            n_candidates = len(next_d[i])
            if (counter + n_candidates) >= k:
                print(next_d[i][k - counter - 1])
                counter += n_candidates
                break
            counter += n_candidates
        d = next_d
        n += 1
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    K = int(input())

    q = queue.Queue()
    for i in range(9):
        q.put(i+1)

    count = 0
    while True:
        count = count+1
        a = q.get()

        if count == K:
            break

        tail = int(str(a)[-1])
        for i in range(10):
            if abs(tail-i) > 1:
                continue
            q.put(int(str(a)+str(i)))

    print(a)

import queue

def main():
    K = int(input())

    q = queue.Queue()
    for i in range(9):
        q.put(i+1)

    count = 0
    while True:
        count = count+1
        a = q.get()

        if count == K:
            break

        tail = int(str(a)[-1])
        for i in range(10):
            if abs(tail-i) > 1:
                continue
            q.put(int(str(a)+str(i)))

    print(a)

if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
k = int(input())
i = 1 
c = 0 

if k > 13000:
    i = 34454557
    c = 13000

while c < k:
  j = str(i)
  if i < 13: 
    c = c + 1 
    #print(c, i)
  else: 
    x = 0
    for n in range(len(j)-1): 判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:
        x = 1
        break
    if x == 0:
      c = c + 1
      #print(c, i)
  i = i + 1 

print(i-1)

k = int(input())
ans = 0 
i = 1 
c = 0 

while c < k:
  j = str(i)
  if i < 13: 
    c = c + 1 
    print(c, i)
  else: 
    x = 0
    for n in range(len(j)-1): 判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:
        x = 1
        break
    if x == 0:
      c = c + 1
      print(c, i)
  i = i + 1 

print(i-1)

k = int(input())
ans = 0 
i = 1 
c = 0 

while c < k:
  j = str(i)
  if i < 13: 
    c = c + 1 
    #print(c, i)
  else: 
    x = 0
    for n in range(len(j)-1): 判定を行う
      if abs(int(j[n]) - int(j[n+1])) > 1:
        x = 1
        break
    if x == 0:
      c = c + 1
      #print(c, i)
  i = i + 1 

print(i-1)

k = int(input())
lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] 

for i in range(k):
    x = lunlun[i]
    if x%10 != 0:
        lunlun.append(x*10+x%10-1)
    lunlun.append(x*10+x%10)
    if x%10 != 9:
        lunlun.append(x*10+x%10+1)
        #print(lunlun)
print(x)

Verdicts: Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
k=int(input())

from collections import deque
g=deque((1,2,3,4,5,6,7,8,9))

b=[[str(k) for k in range(10) if -2<=k-i<3] for i in range(10)]

for i in range(10,1000000):
  i1=list(str(i))
  e1=len(i1)
  for h in range(e1-1):
    if not i1[h+1] in b[int(i1[h])]:
      break
  else:g.append(i)


print(g[k-1])

from collections import deque 
k=int(input())
dq=deque()
for i in range(1,10):
    dq.append(i)

cnt=1
while cnt<k:
    now=dq.popleft()
    if now%10>=1:
        dq.append(now*10+now%10-1)
    dq.append(now*10+now%10)
    if now%10<=8:
        dq.append(now*10+now%10+1)
    cnt+=1
print(dq.popleft())


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

K = int(input())
n = 0
cnt = 0
tmp = 0
while cnt < K:
    n = n + 1
    print(n)
    nDigit = []
    nDiv   = []
    flg = True
    digits = len(str(n))
    tmpN = n
    for i in range(0,digits) :
        nDigit.append(tmpN // (10 ** (digits-i-1)))
        tmpN = tmpN % (10 ** (digits-i-1))
    if len(nDigit) == 1 :
        cnt = cnt + 1
        tmp = n
    else :
        tR = 0
        for i in range(0,len(nDigit)-1) :
            if abs(nDigit[i] - nDigit[i+1]) > 1 :
                flg = False
                tR = i
                i = len(nDigit)
        if flg == True :
            cnt = cnt + 1
            tmp = n
        elif nDigit[tR] - nDigit[tR+1] < 0 :
            n = n - (n % (10 ** (digits - tR))) + (nDigit[tR] + 1) * (10 ** (digits-tR-1)) - 1
        elif nDigit[tR] - nDigit[tR+1] > 0 :
            n = n - (n % (10 ** (digits - tR-1))) + (nDigit[tR] - 1) * (10 ** (digits-tR-2)) - 1


#    print(i,LunList[i])
print(n)


k = int(input())

i = 1
q = []
while i <= k :
    if(i < 10) :
        q.append(i)
    else :
        x = q.pop(0)
        tmp = 10 * x + (x % 10)
        if x % 10 != 0 :
            q.append(tmp-1)
            i+=1
        q.append(tmp)
        if x % 10 != 9 :
            q.append(tmp+1)
            i+=1
    i+=1
print(q.pop(k-i))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
k=int(input());l=list(range(1,10))
for i in l:
  if len(l)==k: print(i); break
  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))
for i in l:
  for j in range(max(i%10-1,0),min(i%10+2,10)):l+=[i*10+j]
  if len(l)>k:break
print(l[k-1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int,input().split())
lst = list(map(int,input().split()))
s = 0
total = sum(lst)
for i in range(n):
  if lst[i] >= total/(4*m):
    s += 1
    
if s >= m:
  print('Yes')
else:
  print('No')
        



import sys
k = int(input())
lst = [[0]*10 for i in range(10)]
for i in range(10):
  lst[0][i] = 1
l_sum = [9]  


for i in range(1,10):
  s = 0
  for j in range(10):
    if j == 0:
      lst[i][j] = lst[i-1][j] + lst[i-1][j+1]
    elif j == 9:
      lst[i][j] = lst[i-1][j] + lst[i-1][j-1] 
    else:
      lst[i][j] = lst[i-1][j-1] + lst[i-1][j] + lst[i-1][j+1] 
      
    if j !=0:
      s += lst[i][j]
  l_sum.append(s+l_sum[-1])
    


i = 0
if k < l_sum[0]:
  print(k)
  sys.exit()
else:
  while True:
    if k < l_sum[i]:
      break
    i += 1
  k = k - l_sum[i-1]
   
  ans = []
  for j in reversed(range(0, i+1)):
    
    if j == i:
      p = 1
      while True:
        if k - lst[j][p] <= 0:
          ans.append(p)
          break
        else:
          k -= lst[j][p]
          p += 1
          
    else:
      if p == 0:
        if k <= lst[j][p]:
          ans.append(p)
        else:
          k -= lst[j][p]
          p += 1
          ans.append(p)
          
      elif p == 9:
        if k <= lst[j][p-1]:
          p = p-1
          ans.append(p)
        else:
          k -= lst[j][p-1]
          ans.append(p)
          
      else:
        if k <= lst[j][p-1]:
          p = p-1
          ans.append(p)
        else:
          k -= lst[j][p-1]
          if k <= lst[j][p]:
            ans.append(p)
          else:
            k -= lst[j][p]
            p = p+1
            ans.append(p)
              
l_s = [str(q) for q in ans]
print(''.join(l_s))
  

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
k = int(input())
lunlun = list(range(1, 10))

for i in range(k - 1):
    a = lunlun[i]
    b = a * 10 + a % 10
    if a % 10 != 0:
        lunlun.append(b - 1)
    lunlun.append(b)
    if a % 10 != 9:
        lunlun.append(b + 1)
print(lunlun)
print(lunlun[k - 1])

k = int(input())
li = [i + 1 for i in range(9)]

c = 0
while len(li) < k:
    if li[c] % 10 != 0:
        li.append(li[c] * 10 + li[c] % 10 - 1)
    li.append(li[c] * 10 + li[c] % 10)
    if li[c] % 10 != 9:
        li.append(li[c] * 10 + li[c] % 10 + 1)
    c += 1
print(li[k - 1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import queue
k = int(input)
q = queue.Queue()

for i in range(1,10):
    q.put(i)

for i in range(k):
    x = q.get()
    if not x%10 == 0:
        q.put(10*x+(x%10)-1)
    q.put(10*x+(x%10))
    if not x%10 == 9:
        q.put(10*x+(x%10)+1)

print(x)


import queue
k = int(input())
q = queue.Queue()

for i in range(1,10):
    q.put(i)

for i in range(k):
    x = q.get()
    if not x%10 == 0:
        q.put(10*x+(x%10)-1)
    q.put(10*x+(x%10))
    if not x%10 == 9:
        q.put(10*x+(x%10)+1)

print(x)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import queue

n = int(input())


q = queue.Queue()

for i in range(1,10):
    q.put(i)

x = 0
for i in range(n):
    x = q.get()
    l = x % 10
    print(x,l)
    if l != 0:
        q.put(x*10 + l - 1)
    q.put(x*10 + l)
    if l != 9:
        q.put(x*10 + l + 1)
        
#while not q.empty():
#    print (q.get())
    
print(x)


import queue

n = int(input())


q = queue.Queue()

for i in range(1,10):
    q.put(i)

x = 0
for i in range(n):
    x = q.get()
    l = x % 10
#    print(x,l)
    if l != 0:
        q.put(x*10 + l - 1)
    q.put(x*10 + l)
    if l != 9:
        q.put(x*10 + l + 1)
        
#while not q.empty():
#    print (q.get())
    
print(x)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
from collections import deque
k=deque([])
z=0
for i in range(1,10):
    k.append(i)
while z<n:
    m=k.pop
    k.popleft
    if m%10!=0:
        k.append(10*m+(m%10)-1)
    k.append(10*m+(m%10))
    if m%10!=9:
        k.append(10*m+(m%10)+1)
print(m)
    


n=int(input())
from collections import deque
k=deque([])
z=9
m=0
if n<10:
    print(n)
    exit()
for i in range(1,10):
    k.append(i)
while z!=n:
    m=k.pop()
    k.popleft
    if m%10!=0:
        ans=10*m+(m%10)-1
        k.append(ans)
        z+=1
        if z==n:
            print(ans)
            exit()
    ans=10*m+(m%10)    
    k.append(ans)
    z+=1
    if z==n:
        print(ans)
        exit()
    if m%10!=9:
        ans=10*m+(m%10)+1
        k.append(ans)
        z+=1
        if z==n:
            print(ans)
            exit()


n=int(input())
from collections import deque
k=deque([])
z=0
m=0
for i in range(1,10):
    k.append(i)
while z<n:
    m=k.pop()
    k.popleft
    if m%10!=0:
        k.append(10*m+(m%10)-1)
    k.append(10*m+(m%10))
    if m%10!=9:
        k.append(10*m+(m%10)+1)
    z+=1
print(m)

n=int(input())
from collections import deque
k=deque([])
z=9
m=0
if n<10:
    print(n)
    exit()
for i in range(1,10):
    k.append(i)
while z!=n:
    m=k.popleft()
    if m%10!=0:
        ans=10*m+(m%10)-1
        k.append(ans)
        z+=1
        if z==n:
            print(ans)
            exit()
    ans=10*m+(m%10)    
    k.append(ans)
    z+=1
    if z==n:
        print(ans)
        exit()
    if m%10!=9:
        ans=10*m+(m%10)+1
        k.append(ans)
        z+=1
        if z==n:
            print(ans)
            exit()


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted