TnT/Multi_CodeNet4Repair huggingface dataset:
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
from collections import deque
sys.setrecursionlimit(10 ** 6)  
to_index = lambda x: int(x) - 1  
print_list_in_2D = lambda x: print(*x, sep="\n")  


def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())


def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))


def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

K = input_int()

if K < 10:  
    print(K)
else:  
    dq = deque([i for i in range(1, 10)])
    count = 0
    while True:
        x = dq.popleft()
        count += 1
        if count == K:
            print(x)
            return
        d = x % 10
        if d != 0:
            dq.append(10 * x + d - 1)
        dq.append(10 * x + d)
        if d != 9:
            dq.append(10 * x + d + 1)

import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)  
to_index = lambda x: int(x) - 1  
print_list_in_2D = lambda x: print(*x, sep="\n")  


def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())


def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))


def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

K = input_int()

if K < 10:  
    print(K)
else:  
    dq = deque([i for i in range(1, 10)])
    count = 0
    while True:
        x = dq.popleft()
        count += 1
        if count == K:
            print(x)
            exit()
        d = x % 10
        if d != 0:
            dq.append(10 * x + d - 1)
        dq.append(10 * x + d)
        if d != 9:
            dq.append(10 * x + d + 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
input=sys.stdin.readline
K = int(input())
LEN = 3234566667
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def enqueue(Q,x,tail):
    Q[tail] = x       
    if tail+1 == LEN: 
        tail = 0
    else:
        tail += 1
    return tail
def dequeue(Q,head):
    x = Q[head]
    if head+1 == LEN:
        head = 0
    else:
        head += 1
    return x,head
Q = [1,2,3,4,5,6,7,8,9]+[0]*(LEN-9)
head = 0
tail = 9

i = 0
while i < K:
    x,head = dequeue(Q,head)
    if x % 10 == 0:
        tail = enqueue(Q,10*x,tail)
        tail = enqueue(Q,10*x+1,tail)
    elif x % 10 == 9:
        tail = enqueue(Q,10*x+8,tail)
        tail = enqueue(Q,10*x+9,tail)
    else:
        y = x%10
        tail = enqueue(Q,10*x+y-1,tail)
        tail = enqueue(Q,10*x+y,tail)
        tail = enqueue(Q,10*x+y+1,tail)
    i += 1
print(x)

import sys
input=sys.stdin.readline
K = int(input())
LEN = 32345666
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def enqueue(Q,x,tail):
    Q[tail] = x       
    if tail+1 == LEN: 
        tail = 0
    else:
        tail += 1
    return tail
def dequeue(Q,head):
    x = Q[head]
    if head+1 == LEN:
        head = 0
    else:
        head += 1
    return x,head
Q = [1,2,3,4,5,6,7,8,9]+[0]*(LEN-9)
head = 0
tail = 9

i = 0
while i < K:
    x,head = dequeue(Q,head)
    if x % 10 == 0:
        tail = enqueue(Q,10*x,tail)
        tail = enqueue(Q,10*x+1,tail)
    elif x % 10 == 9:
        tail = enqueue(Q,10*x+8,tail)
        tail = enqueue(Q,10*x+9,tail)
    else:
        y = x%10
        tail = enqueue(Q,10*x+y-1,tail)
        tail = enqueue(Q,10*x+y,tail)
        tail = enqueue(Q,10*x+y+1,tail)
    i += 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):
from collections import deque
k=int(input())
deq=deque([1,2,3,4,5,6,7,8,9])
for in in range(k):
  a=deq.popleft()
  if not a%10==0:
    deq.append(a*10+a%10-1)
  deq.append(a*10+a%10)
  if a%10==9:
    deq.append(a*10+a%10+1)
print(a)
    
  

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


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


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


Verdicts: Runtime Error

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):
x = int(input())

p = []
for i in range(1, 10):
  p.append(i)

ans = 0
index = x

while 1:
    if index <= len(p):
      break
    index -= len(p)
    for i in p:
      for j in range(-1, 2):
          d = i % 10 + j
          if d < 0 or d > 9:
              continue

          nx = i * 10 + d
          p.append(nx)

ans = p[x - 1]
print(ans)



x = int(input())

p = [None for _ in range(100)]

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

def getByKeta(n):
    for i in p[n-1]:
        for j in range(-1, 2):
          d = i % 10 + j
          if d < 0 or d > 9:
              continue

          yield i * 10 + d

for i in range(2, 11):
    p[i] = tuple(getByKeta(i))

ans = 0
for i in range(1, 11):
    if x <= len(p[i]):
        ans = p[i][x-1]
        break
    x -= len(p[i])
print(ans)

# p = []

#   p.append(i)

# ans = 0
# index = x

# while 1:
#     if index <= len(p):
#       break
#     index -= len(p)

#       for j in range(-1, 2):

#           if d < 0 or d > 9:
#               continue


#           p.append(nx)

# print(p)
# print(len(p))
# ans = p[1]
# print(ans)



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())

count = 0

for i in range(1,10**10):
    l = len(str(i))
    if l == 1:
        count +=1
        ans = i
        if count == k:
            print(ans)
            break
        else:
            continue
    else:
        for j in range(l-1):
            if not abs(int(str(i)[j]) - int(str(i)[j+1])) <= 1:
                continue
            elif j ==l-1:
                count +=1
                ans = i
    if count == k:
        print(ans)
        break

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 i == k-1:
        break
    else:
        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: 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):
import sys
from itertools import accumulate
K = int(input())

MAX = 22
dp = [[0]*10 for _ in [0]*MAX]

for j in range(0, 10):
    dp[1][j] = 1

for i in range(2, MAX):
    for j in range(1, 9):
        dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]
    dp[i][0] = dp[i-1][0] + dp[i-1][1]
    dp[i][9] = dp[i-1][8] + dp[i-1][9]

acc = [[] for _ in [0]*MAX]
for i in range(1, MAX):
    acc[i] = accumulate(dp[i])


num = [0]
for i in range(1, MAX):
    num.append(num[i-1] + sum(dp[i][1:]))

print(dp[:6])
print(num)

cnt = 0
for i, n in enumerate(num):
    if n < K:
        keta = i+1
        cnt = n
    else:
        break

print(keta, cnt)
ans = 0

rg = range(1, 10)
p = 1
for i in range(keta, 0, -1):
    for j in rg:
        print('keta', i, 'suuji', j, 'cnt', cnt, 'dp', dp[i][j], 'ans', ans)
        if cnt + dp[i][j] < K:
            flg = True
            p = j+1
            cnt += dp[i][j]
        else:
            break

    ans += 10**(i-1)*p

    rg = range(max(0, p-1), min(10, p+2))
    p = p-1

print(ans)


from collections import deque

K = int(input())

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

cnt  = 0


while q:
    x = q.popleft()

    cnt += 1
    if cnt == K:
        print(x)
        break

    y = x % 10
    z = 10*x+y
    if y != 0:
        q.append(z-1)
    q.append(z)
    if y != 9:
        q.append(z+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):
k = int(input())
cand = [[1,2,3,4,5,6,7,8,9]]
for i in range(9):
  tmp = []
  for val in cand[-1]:
    if val % 10 != 0:
      tmp.append(val*10 + (val%10 - 1))
    tmp.append(val*10 + (val % 10))
    if val % 10 != 9:
      tmp.append(val*10 + (val%10 + 1))
  cand.append(tmp)

ans = []
for j in range(len(cand)):
  for val in cand[i]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])


k = int(input())
cand = [[1,2,3,4,5,6,7,8,9]]
for i in range(9):
  tmp = []
  for val in cand[-1]:
    if val % 10 != 0:
      tmp.append(val*10 + (val%10 - 1))
    tmp.append(val*10 + (val % 10))
    if val % 10 != 9:
      tmp.append(val*10 + (val%10 + 1))
    cand.append(tmp)

ans = []
for j in range(len(cand)):
  for val in cand[i]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])

k = int(input())
cand = [[1,2,3,4,5,6,7,8,9]]
for i in range(9):
  tmp = []
  for val in cand[-1]:
    if val % 10 != 0:
      tmp.append(val*10 + (val%10 - 1))
    tmp.append(val*10 + (val % 10))
    if val % 10 != 9:
      tmp.append(val*10 + (val%10 + 1))
  cand.append(tmp)

ans = []
for j in range(len(cand)):
  for val in cand[j]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])


Verdicts: Wrong Answer

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 itertools
digits1 = [str(i) for i in range(1,10)]
digits2 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits1]))
digits3 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits2]))
digits4 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits3]))
digits5 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits4]))
digits6 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits5]))
digits7 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits6]))
digits8 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits7]))
digits9 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits8]))
digits10 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits9]))
index = digits1 + digits2 + digits3 + digits4 + digits5 + digits6 + digits7 + digits8 + digits9 + digits10
K = int(input())
print(index[K-1])

import itertools
def addLunLun(str_num):
    last_digit = int(str_num[len(str_num)-1:])
    if last_digit == 0:
        return [str_num+"0",str_num+"1"]
    elif last_digit == 9:
        return [str_num+"8",str_num+"9"]
    else:
        return [str_num + str(last_digit-1),str_num + str(last_digit),str_num + str(last_digit+1)]
    
digits1 = [str(i) for i in range(1,10)]
digits2 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits1]))
digits3 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits2]))
digits4 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits3]))
digits5 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits4]))
digits6 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits5]))
digits7 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits6]))
digits8 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits7]))
digits9 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits8]))
digits10 = list(itertools.chain.from_iterable([addLunLun(i) for i in digits9]))
index = digits1 + digits2 + digits3 + digits4 + digits5 + digits6 + digits7 + digits8 + digits9 + digits10
K = int(input())
print(index[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):
que = queue.Queue()

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

for i in range(1, k + 1):
    ans = que.get()
    keta1 = ans % 10
    if keta1 == 0:
        append_list = [ans * 10, ans * 10 + 1]
    elif keta1 == 9:
        append_list = [ans * 10 + 8, ans * 10 + 9]
    else:
        append_list = [ans * 10 + keta1 - 1, ans * 10 + keta1, ans * 10 + keta1 + 1]
    for item in append_list:
        que.put(item)
print(ans)

import queue

k = int(input())

import queue

que = queue.Queue()

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

for i in range(1, k + 1):
    ans = que.get()
    keta1 = ans % 10
    if keta1 == 0:
        append_list = [ans * 10, ans * 10 + 1]
    elif keta1 == 9:
        append_list = [ans * 10 + 8, ans * 10 + 9]
    else:
        append_list = [ans * 10 + keta1 - 1, ans * 10 + keta1, ans * 10 + keta1 + 1]
    for item in append_list:
        que.put(item)
print(ans)

Verdicts: Runtime Error

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
k = int(input())
d = deque()
d += [1,2,3,4,5,6,7,8,9]
for i in range(k):
#     print(d, now)
    now = d.popleft()
    if now%10 != 0:
        d.append(10 * now + now % 10 - 1)
    d.append(10 * now + now % 10)
    if now%10 != 9:
        d.append(10 * now + now % 10 + 1)
print(k, now)

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

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())




k = int(input())
n = []

def dfs(num, A):
  A.append(num)

  if(len(str(num)) == 10):
    return 0

  for i in range(-1, 2):
    s = num%10 + i
    if(s >= 0 and s <= 9):
      dfs(num * 10 + s, A)

  return 0

for i in range(1, 10):
  dfs(i, n)

n = sorted(n)

print(n[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):
k = int(input())
stack = list(range(1,10))
for i in range(k):
  num = stack.pop(0)
  if (m:=num%10) == 0:
    stack.append([num*10 + m,num*10+m+1])
  elif m == 9:
    stack.append([num*1 + m -1,num*10 + m])
  else:
    stack.append([num*10 + m -1,num*10 + m, num*10+ m + 1])
print(num)

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    k = int(input())
    from collections import deque
    que = deque(range(1, 10))
    for i in range(k):
        now = que.popleft()
        r = now%10
        nx = now*10
        if r == 0:
            for j in [0, 1]:
                que.append(nx+r+j)
        elif r == 9:
            for j in [-1, 0]:
                que.append(nx+r+j)
        else:
            for j in [-1, 0, 1]:
                que.append(nx+r+j)
    print(now)

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):
import queue

k = int(input())
q = queue.Queue()
for i in range(1,9):
  q.put(i)

n = 0
while True:
  val = q.get()
  if val % 10 != 0:
    q.put(10 * val + (val % 10) - 1)
  q.put(10 * val + (val % 10))
  if val % 10 != 9:
    q.put(10 * val + (val % 10) + 1)
  
  n += 1
  if n == k:
    print(val)
    break

import queue

k = int(input())
q = queue.Queue()
for i in range(1,9):
  q.put(i)

n = 0
while True:
  val = q.get()
  if val % 10 != 0:
    q.put(10 * val + (val % 10) - 1)
  q.put(10 * val + (val % 10))
  if val % 10 != 9:
    q.put(10 * val + (val % 10) + 1)
  
  n += 1
  if n == k:
    print(val)
    break

mport queue

k = int(input())
q = queue.Queue()
for i in range(1,9):
  q.put(i)

n = 0
while True:
  val = q.get()
  if val % 10 != 0:
    q.put(10 * val + (val % 10) - 1)
  q.put(10 * val + (val % 10))
  if val % 10 != 9:
    q.put(10 * val + (val % 10) + 1)
  
  n += 1
  if n == k:
    print(val)
    break

import queue

k = int(input())
q = queue.Queue()
for i in range(1,10):
  q.put(i)

n = 0
while True:
  val = q.get()
  n += 1
  if n == k:
    print(val)
    break

  if val % 10 != 0:
    q.put(10 * val + (val % 10) - 1)
  q.put(10 * val + (val % 10))
  if val % 10 != 9:
    q.put(10 * val + (val % 10) + 1)
  
  

Verdicts: Wrong Answer

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):
def Add_(N):
    M = N
    C = 1
    while M > 10:
        M = M // 10
        C += 1
    if M == 1:
        return [ M * 10**C + N,(M+1) * 10**C + N ]
    elif M == 9:
        return [ (M-1) * 10**C + N, M * 10**C + N ]
    else:
        return [(M-1) * 10**C + N, M * 10**C + N,(M+1) * 10**C + N ]

X = int(input())
R = [1,2,3,4,5,6,7,8,9]
R_list = [[0]]
R_list.append(R)
n = 9
d = 1
while n < X:
    list1 = R_list[-2] 
    list1 = list(map(lambda x: x + 10**d, list1) )
    list_ = [10 ** d]
    list_.extend(list1)
    for i in R_list[-1]:
        temp = Add_(i)
        list_.extend(temp)
        n += len(temp)
    d += 1
    R_list.append(list_)

R = list()
for list_ in R_list:
    R.extend(list_)
R.sort()
print(R[X])

def add(N):
    n = N % 10
    ret = N * 10
    if n == 0:
        return [ret, ret + 1]
    elif n == 9:
        return [ret + 9,ret + 8]
    else:
        return [ret + n - 1, ret + n, ret + n + 1]

X = int(input())
l = [1,2,3,4,5,6,7,8,9]
lists = list()
lists.append(l)
n = 9
while n < X:
    list_ = lists[-1]
    templist = list()
    for l_ in list_:
        vals = add(l_)
        n += len(vals)
        templist.extend(vals)
    lists.append(templist)

R = list()
for list_ in lists:
    R.extend(list_)
R.sort()
print(R[X-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):
from collections import deque
def main(k):
    q = deque([])
    for i in range(10):
        q.append(i)
    
    count = 0
    top = -1
    while True:
        top = q.popleft()

        count += 1
        if count == k:
            return top

        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)

    return top

k = int(input())
main(k)

from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()

        count += 1
        if count == k:
            return top

        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)

    return top

main(k)

from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()

        count += 1
        if count == k:
            return top

        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)

    return top
k = int(input())
main(k)

from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()
 
        count += 1
        if count == k:
            return top
 
        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)
 
    return top
k = int(input())
print(main(k))

Verdicts: Wrong Answer

Runtime Error

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())
cou = 0
while True:
    cou += 1
    t = q.get()
    if cou == k:
        print(t)
        exit()
    if t % 10 == 0:
        q.put(t*10)
        q.put(t*10 + 1)
    elif t % 10 == 9:
        q.put(t*10 + 8)
        q.put(t*10 + 9)
    else:
        s = t % 10
        q.put(t*10 + s -1)
        q.put(t*10 + s)

import queue

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

k = int(input())
cou = 0
while True:
    cou += 1
    t = q.get()
    if cou == k:
        print(t)
        exit()
    if t % 10 == 0:
        q.put(t*10)
        q.put(t*10 + 1)
    elif t % 10 == 9:
        q.put(t*10 + 8)
        q.put(t*10 + 9)
    else:
        s = t % 10
        q.put(t*10 + s -1)
        q.put(t*10 + s)
        q.put(t*10 + 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())
queue = deque([1,2,3,4,5,6,7,8,9])
count = 1
while count <= K:
  num = queue.popleft()
  if num%10!=0:
    queue.append(num*10+num%10-1)
  queue.append(num*10+num%10)
  if num%!=9:
    queue.append(num*10+num%10+1)
  
print(num)

from collections import deque
K = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])
count = 1
while count <= K:
  num = queue.popleft()
  if num%10!=0:
    queue.append(num*10+num%10-1)
  queue.append(num*10+num%10)
  if num%10!=9:
    queue.append(num*10+num%10+1)
  count+=1
  
print(num)

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 d1(x):
    y = x % 10
    if y == 0:
        return [0, 1]
    elif y == 9:
        return [8, 9]
    else:
        return [y-1, y, y+1]


K = int(input())

runrun = []
N = 0
digit = 0
while N < K:
    d_i = []
    if digit == 0:
        for i in range(1, 10):
            d_i.append(i)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1
    else:
        tmp = runrun[digit-1]
        for x in tmp:
            for y in d1(x):
                d_i.append(10*x+y)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1

print(runrun[-1][K-N+1])

def d1(x):
    y = x % 10
    if y == 0:
        return [0, 1]
    elif y == 9:
        return [8, 9]
    else:
        return [y-1, y, y+1]


K = int(input())

runrun = []
N = 0
digit = 0
while N < K:
    d_i = []
    if digit == 0:
        for i in range(1, 10):
            d_i.append(i)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1
    else:
        tmp = runrun[digit-1]
        for x in tmp:
            for y in d1(x):
                d_i.append(10*x+y)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1

print(runrun[-1][K-N-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):
k = int(input())
time = 1

dp0 = [1]#0,9
dp1 = [8]#1~8
p = [9]

for i in range(100):
    dp0.append(dp0[i]*2 + 2)
    dp1.append(dp1[i]*3 - 2)
    p.append(dp0[i+1] + dp1[i+1] + p[i])

    if p[len(p)-1] > k:
        break

#print(len(p))
s = k - p[len(p)-2]
w = [0]*len(p)
print(s,w)


import collections

k = int(input())
time = 1

q = collections.deque()

q.extend([1,2,3,4,5,6,7,8,9])

while(time <= k):

    i = q.popleft()
    #print(i)
    time += 1

    
    if i % 10 != 0:
        q.append(i*10 + i%10 - 1)

    
    q.append(i*10 + i%10)

    
    if i % 10 != 9:
        q.append(i*10 + i%10 + 1)

print(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())
A = "0123456789"
S = [i for i in range(1,10)]
Q = [str(i) for i in range(1,10)]
while Q:
    q = Q.pop(0)
    D = []
    if q[-1]=="0":
        D = [q+"0",q+"1"]
    elif q[-1]=="9":
        D = [q+"0",q+"1"]
    else:
        a = A.index(q[-1])
        D = [q+A[a-1],q+A[a],q+A[a+1]]
    for d in D:
        S.append(int(d))
        if len(d)<11:
            Q.append(d)
S.sort()
print(S[K-1])

K = int(input())
A = "0123456789"
S = []
def f(n):
    global A,S
    if len(n)>10:return
    if n[-1]=="0":
        D=(n+"0",n+"1")
    elif n[-1]=="9":
        D=(n+"9",n+"8")
    else:
        a = A.index(n[-1])
        D=(n+A[a],n+A[a-1],n+A[a+1])
    for d in D:
        S.append(int(d))
        f(d)

for i in range(1,10):
    S.append(i)
    f(str(i))
S.sort()
print(S[K-1])

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())
A=[[1,1,1,1,1,1,1,1,1,1]]
for i in range(9):
    Ai=[]
    Ai.append(A[i][0]+A[i][1])
    for j in range(8):
        Ai.append(A[i][j]+A[i][j+1]+A[i][j+2])
    Ai.append(A[i][7]+A[i][8])
    A.append(Ai)
c=[]
for i in range(len(A)):
    c.append(sum(A[i][1:10]))
l=1 #length of number
while k>c[l-1]:
    k=k-c[l-1]
    l+=1
seq=[]

n=1 
while k>A[l-1][n]:
    k=k-A[l-1][n]
    n+=1
seq.append(n)#head number

for i in range(l-1):
    if seq[i]==0:
        j=0
        while k>A[l-2-i][j]:
            k=k-A[l-2-i][j]
            j+=1
        seq.append(j)
    else:
        j=seq[i]-1
        while k>A[l-2-i][j]:
            k=k-A[l-2-i][j]
            j+=1        
        seq.append(j)

for i in range(len(seq)):
    print(seq[i],end="")

k=int(input())
A=[[1,1,1,1,1,1,1,1,1,1]]
for i in range(9):
    Ai=[]
    Ai.append(A[i][0]+A[i][1])
    for j in range(8):
        Ai.append(A[i][j]+A[i][j+1]+A[i][j+2])
    Ai.append(A[i][7]+A[i][8])
    A.append(Ai)
c=[]
for i in range(len(A)):
    c.append(sum(A[i][1:10]))

print(c)
l=1 #length of number
while k>c[l-1]:
    k=k-c[l-1]
    l+=1
seq=[]

n=1 
while k>A[l-1][n]:
    k=k-A[l-1][n]
    n+=1
seq.append(n)#head number

for i in range(l-1):
    if seq[i]==0:
        j=0
        while k>A[l-2-i][j]:
            k=k-A[l-2-i][j]
            j+=1
        seq.append(j)
    else:
        j=seq[i]-1
        while k>A[l-2-i][j]:
            k=k-A[l-2-i][j]
            j+=1        
        seq.append(j)

for i in range(len(seq)):
    print(seq[i],end="")

import queue

k=int(input())

q=queue.Queue()

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

c=1

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

print(c)

Verdicts: 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())

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

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

from collections import deque
k = int(input())
q = deque(list(range(1, 10)))
for _ in range(k-1):
	d = q.popleft()
	if d%10 > 0:
		q.append(d*10 + d%10 - 1)
	q.append(d*10 + d%10)
	if d%10 < 9:
		q.append(d*10 + d%10 + 1)
print(q.popleft())

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())
A=[1,2,3,4,5,6,7,8,9]
I=0
while I<=K:
    if not A[I]%10==0:
        A.append(A[I]%10+10*A[I]-1)
    A.append(A[I]%10+10*A[I])
    if not A[I]%10==9:
        A.append(A[I]%10+10*A[I]+1)
    I+=1
    if len(A)>=K:
      break
print(A[I])

K=int(input())
A=[1,2,3,4,5,6,7,8,9]
I=0
while I<=K:
    if not A[I]%10==0:
        A.append(A[I]%10+10*A[I]-1)
    A.append(A[I]%10+10*A[I])
    if not A[I]%10==9:
        A.append(A[I]%10+10*A[I]+1)
    I+=1
    if len(A)>=K:
      break
print(A[I])

K=int(input())
A=[1,2,3,4,5,6,7,8,9]
I=0
while I<=K:
    if not A[I]%10==0:
        A.append(A[I]%10+10*A[I]-1)
    A.append(A[I]%10+10*A[I])
    if not A[I]%10==9:
        A.append(A[I]%10+10*A[I]+1)
    if len(A)>=K:
      break
    I+=1
print(A[K-1])

Verdicts: Wrong Answer

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 math

num = int(input())

box = [1,2,3,4,5,6,7,8,9]
k=0

while True:
    
    if len(box)==num:
        print(box[num-1])
        break

    k = k+1 
    k1 = str(k)
    for i in range(len(k1)-1):
        if i == len(k1)-2:
            if abs(int(k1[i])-int(k1[i+1]))<=1:
                box.append(k)
        if abs(int(k1[i])-int(k1[i+1]))<=1:
            continue
        else:break

print(box)


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

while True:
    if  len(a) >= N:
        print(a[N-1])
        break
    i = i + 1
    n = int(str(a[i])[-1])
    x = a[i]*10 + n-1
    y = a[i]*10 + n
    z = a[i]*10 + n+1
    if n != 9 and n != 0:
        w = (x,y,z)
        a.extend(w)
    elif n == 9:
        w = (x,y)
        a.extend(w)
    elif n == 0:
        w = (y,z)
        a.extend(w)


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):
def dfs(r):
    global l
    if len(r) == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(str(i))
print(sorted(l)[k])

def dfs(d, r):
    global l
    if d == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(d + 1, r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(1, str(i))
print(sorted(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):
import heapq

k = int(input())

lunlun = [1,2,3,4,5,6,7,8,9]
heapq.heapify(lunlun)

for i in range(1,10**5):
    x = heapq.heappop(lunlun) 
    y = x % 10
    if i == k :
        break
    if y != 0:
         heapq.heappush(lunlun, x * 10 + y- 1)
    heapq.heappush(lunlun,10*x+y)
    if y != 9:
        heapq.heappush(lunlun, x * 10 + y + 1)
print(lunlun)
print(x)



import heapq

k = int(input())
i=0
lunlun = [1,2,3,4,5,6,7,8,9]
heapq.heapify(lunlun)

while True:
    i += 1
    if i == k:
        break
    x = heapq.heappop(lunlun)
    if x % 10 != 0:
        heapq.heappush(lunlun,10 * x + (x % 10) -1)
    heapq.heappush(lunlun,10 * x + (x % 10))
    if x % 10 != 9:
        heapq.heappush(lunlun,10 * x + (x % 10) +1)

print(lunlun[0])

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 sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())

N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 9
for i in range(len(A)):
    bts(A[i], 1, 100)
# print(cnt1)


# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())

N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 9
for i in range(len(A)):
    bts(A[i], 1, 10)
# print(cnt1)


# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())

N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 0
for k in range(1, 11):
    for i in range(len(A)):
        bts(A[i], 1, k)
# print(cnt1)


Verdicts: Wrong Answer

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 sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = 0

def dfs(i, s, p):
    if i == 0:
        cnt = cnt + 1
        if cnt == K:
            print(s)
            exit()
    if s == 0:
        for ii in range(10):
            dfs(i-1, s+ii*10**(i-1), ii)
    else:
        for ii in RUN[p]:
            dfs(i-1, s+ii*10**(i-1), ii)

dfs(10, 0, 0)

import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = 0

def dfs(i, s, p):
    if i == 0:
        cnt = cnt + 1
        if cnt == K:
            print(s)
            exit()
    if s == 0:
        for ii in range(10):
            dfs(i-1, s+ii*10**(i-1), ii)
    else:
        for ii in RUN[p]:
            dfs(i-1, s+ii*10**(i-1), ii)

dfs(10, 0, 0)

import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = -1

def dfs(i, s, p, cnt):
    if i == 0:
        cnt += 1
        if cnt == K:
            print(s)
            exit()
        else:
            return cnt
    if s == 0:
        for ii in range(10):
            cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)
    else:
        for ii in RUN[p]:
            cnt = dfs(i-1, s+ii*10**(i-1), ii, cnt)

    return cnt

dfs(10, 0, 0, cnt)

Verdicts: 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):
import queue

K = int(input())
A = queue.Queue()

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

num = 0
while num < K:
        emp = A.get()
        var = emp % 10
        if var != 0:
                A.put(emp*10+var-1)
        A.put(10*emp)
        if var != 9:
                A.put(emp*10+var+1)
        num += 1
        print(num, emp)

print(emp)

import queue

K = int(input())
A = queue.Queue()

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

num = 0
while num < K:
        emp = A.get()
        var = emp % 10
        if var != 0:
                A.put(emp*10+var-1)
        A.put(10*emp+var)
        if var != 9:
                A.put(emp*10+var+1)
        num += 1

print(emp)

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

k = int(input())
q = deque(range(1, 10))

for i in range(k-1):
    
    x = q.popleft()
    y = int(str(x)[-1])
    if y-1 >= 0:
        print(int(str(x)+str(y-1)))
        q.append(int(str(x)+str(y-1)))
    q.append(int(str(x)+str(x)[-1]))
    if y+1 < 10:
        q.append(int(str(x)+str(y+1)))

    print(q)




from collections import deque

k = int(input())
q = deque(range(1, 10))

for i in range(k-1):
    
    x = q.popleft()
    y = int(str(x)[-1])
    if y-1 >= 0:
        q.append(int(str(x)+str(y-1)))
    q.append(int(str(x)+str(x)[-1]))
    if y+1 < 10:
        q.append(int(str(x)+str(y+1)))

print(q[0])




Verdicts: Runtime Error

Accepted