Problem:


Score : 400 points

Problem Statement

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.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.



Sample input:
15


Sample output:
23

Submission status: Runtime Error

Solution code:
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
    
    
    i=i+1
    if i==100000:
        break
print(a[k-1])

Submission status: Runtime Error

Solution code:
k = int(input()) 
 
 lunlun = [i for i in range(1, 10)]
 
 p = 0 

 def generate_lunlun(p):
     last = p % 10
     if last - 1 >= 0:
         yield p * 10 + last - 1
    yield p * 10 + last
    if last + 1 <= 9:
        yield p * 10 + last + 1 

while len(lunlun) < k:
    for new_lunlun in generate_lunlun(lunlun[p]):
        lunlun.append(new_lunlun)
    p += 1

print(lunlun[k-1])

Submission status: Runtime Error

Solution code:
from collections import deque

k = int(input())
a = deque(range(1, 10))
cnt = 0

for i in range(k):
    x = a.popleft()
    mod = x % 10
    if mod != 0:
        a.append(x*10 + mod -1)
    a.append(x * 10 + mod)
    if mod != 9:
        a.append(x*10 + mod + 1)
    print(a)

print(x)

Submission status: Runtime Error

Solution code:
K = int(input())

count = 9
lunlun = [["0","1","2","3","4","5","6","7","8","9"]]
ans = [0,1,2,3,4,5,6,7,8,9]

keta = 2

while count < K:
    lunlun.append([])
    for a in lunlun[keta - 2]:
        t = a[0]
        if int(t) - 1 >= 0:
            lunlun[keta - 1].append(str(int(t)-1)+str(a))
            count += 1
        lunlun[keta - 1].append(str(int(t))+str(a))
        count += 1
        if int(t) + 1 <= 9:
            lunlun[keta - 1].append(str(int(t)+1)+str(a))
            count += 1
    lunlun[keta - 1].sort()
    for b in lunlun[keta - 1]:
        ans.append(int(b))
    keta += 1
ansx = list(set(ans))
ansx.sort()
print(ansx[K])

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())
lis = ['1','2','3','4','5','6','7','8','9']
lis = np.array(lis)
if K == 1:
  print(1)
elif K < 10:
  print(K)
else:
  count = 9
  sub_count = 0
  while count < K:
    tmp = lis[sub_count]
    if tmp[-1] == '9':
      count += 2
      lis.append(tmp + '8')
      lis.append(tmp + '9')
      sub_count += 1
    elif  tmp[-1] == '0':
      count += 2
      lis.append(tmp + '0')
      lis.append(tmp + '1')
      sub_count += 1
    else:
      count += 3
      for i in range(-1,2):
        lis.append(tmp + str(int(tmp[-1]) + i))
      sub_count += 1
  print(lis[count-1])

Submission status: Runtime Error

Solution code:
import queue
K = int(intut())
q = queue.Queue()
ans = 0
for i in range(9):
  q.put(i + 1)
for i in range(K):
  ans = q.get()
  if tmp % 10 == 0:
    q.put(10 * tmp)
    q.put(10 * tmp + 1)
  elif tmp % 10 == 9:
    q.put(10 * tmp + 8)
    q.put(10 * tmp + 9)
  else:
    for t in range(-1,2):
      q.put(10 * tmp + tmp % 10 + t)
print(ans)

Submission status: Runtime Error

Solution code:
import queue
K = int(intut())
q = queue.Queue()
for i in range(9):
  q.put(i + 1)
for i in range(K):
  tmp = q.get()
  if tmp % 10 == 0:
    q.put(10 * tmp)
    q.put(10 * tmp + 1)
  elif tmp % 10 == 9:
    q.put(10 * tmp + 8)
    q.put(10 * tmp + 9)
  else:
    for t in range(-1,2):
      q.put(10 * tmp + tmp % 10 + t)
print(tmp)

Submission status: Runtime Error

Solution code:
k = int(input())

def lunlun(num:int)->bool:
  s= str(num)
  for i in range(len(s)-1):
    if abs(s[i+1]-s[i])>2:
      return False
  return True

count=0
num=1
res=0
while(count<k):
  if lunlun(num):
    count+=1#no of lunluns
    res=num
  num+=1
print(res)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from collections import deque

def make_lunlun():
    lst = []
    que = deque([1,2,3,4,5,6,7,8,9])
    for i in range(10):
        str_num = str(que.popleft())
        str_one = str_num[-1]
        a = str(int(str_one) - 1)
        b = str(int(str_one) + 1)
        #minus = int(str_num + a)
        same = int(str_num + str_one)
        #plus = int(str_num + b)
        if 0 < int(str_one) < 9:
            minus = int(str_num + a)
            plus = int(str_num + b)
            que.extend([minus,same,plus])
            lst.extend([minus,same,plus])
        elif int(str_one) == 0:
            plus = int(str_num + b)
            que.extend([same,plus])
            lst.extend([same,plus])
        else:
            minus = int(str_num + a)
            que.extend([minus,same])
            lst.extend([minus,same])
    print(lst[K - 10])    

K = int(input())
if K <= 12:
    print(K)
else:
    make_lunlun()

Submission status: Runtime Error

Solution code:
k =int(input())
ls=range(1,10)
d = 9
while d<k:
  ls.append([])

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
K = int(input())

queue = list(range(1, 10))

if K < 10:
    print(K)
else:
    i = 0
    while K > len(queue):
        if queue[i] % 10 != 0:
            l = 10 * queue[i] + queue[i] % 10 - 1
            queue.append(l)
        
        l = 10 * queue[i] + queue[i] % 10
        queue.append(l)
        
        if queue[i] % 10 != 9:
            l = 10 * queue[i] + queue[i] % 10 + 1
            queue.append(l)
        
        i += 1

    print(queue[K])

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())
lis = [1,2,3,4,5,6,7,8,9]
lis = np.array(lis)
  
if K < 10:
  print(K)
    
else:
  count = 9
  sub_count = 0
  while count < K:
    tmp = lis[sub_count]
    if tmp % 10 == 9:
      count += 2
      lis.append(tmp * 10  + 8)
      lis.append(tmp * 10 + 9)
      sub_count += 1
    elif  tmp % 10== 0:
      count += 2
      lis.append(tmp * 10 )
      lis.append(tmp * 10 + 1)
      sub_count += 1
    else:
      count += 3
      for i in range(-1,2):
        lis.append(tmp * 10 + tmp % 10 + i)
      sub_count += 1
  print(lis[count-1])

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())
lis = [1,2,3,4,5,6,7,8,9]
lis = np.array(lis)
  
if K < 10:
  print(K)
    
else:
  count = 9
  sub_count = 0
  while count < K:
    tmp = lis[sub_count]
    if tmp % 10 == 9:
      count += 2
      lis.append(tmp * 10  + 8)
      lis.append(tmp + 9)
      sub_count += 1
    elif  tmp % 10== 0:
      count += 2
      lis.append(tmp * 10 + 0)
      lis.append(tmp * 10 + 1)
      sub_count += 1
    else:
      count += 3
      for i in range(-1,2):
        lis.append(tmp * 10 + tmp % 10 + i)
      sub_count += 1
  print(lis[count-1])

Submission status: Runtime Error

Solution code:
import sys
n, k = map(int, input().split())
p = list(map(int, input().split()))
if n == k:
    print((sum(p) + k) / 2)
    sys.exit(0)
saveSum = sum(p[0:k])
M = 0
for i in range(k, len(p)):
    saveSum = saveSum + p[i] - p[i - k]
    print(p[i-k])
    if saveSum > M:
        M = saveSum
print((k+M)/2)

Submission status: Runtime Error

Solution code:
#キューを使います
from collections import deque

#関数f:入力xの1の位がyだとした時、「xの末尾に(y-1)を付加したもの」を出力
def f(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return s+str(y-1) #yから1引いて、元の文字列の末尾に追加

#関数g:入力xの1の位がyだとした時、「xの末尾にyを付加したもの」を出力
def g(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return s+str(y) #yを元の文字列の末尾に追加

#関数h:入力xの1の位がyだとした時、「xの末尾にy+1を付加したもの」を出力
def h(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return s+str(y+1) #y+1を元の文字列の末尾に追加

#入力受け取り
K=int(input())

#キューの準備
q=deque()

#キューには1から9の整数を先に入れておく
for i in range(1, 10):
  q.append(i)
  
#キューから数字を取り出し、末尾に数字を付けることで作れるルンルン数をキューに追加する
#この操作をK-1回行う
for i in range(K-1):
  num=q.popleft()　#キューから数字を取り出す
  if v%10!=0: #末尾が0の時は、末尾から-1した数字を付加してもルンルン数とならないため除外
    q.append(f(num))
    
  q.append(g(num))
  
  if v%10!=9: #末尾が9の時は、末尾に+1した数字を付加してもルンルン数とならないため除外
    q.append(h(num))
    
print(q.popleft()) #K回目に出てくるルンルン数を出力

Submission status: Runtime Error

Solution code:
#input
K = int(input())

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

for i in range(1, K+2):
    x = q.get()
    if x % 10 != 0:
        q.put(10*x + (x % 10)-1)
    q.put(10*x+(x % 10))
    if x % 10 != 9:
        q.put(10*x + (x % 10)+1)
    if i == K:
        print(x)

Submission status: Runtime Error

Solution code:
import headq

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

Submission status: Runtime Error

Solution code:
k = int(input())
num = 0
for _ in range(k):
  num += 1
  digit = [int(digit) for digit in str(num)]
  len_digit = len(digit)
  for i in range(1, len_digit):
    if digit[-i] > min(digit[-i-1] + 1, 9):
      digit[-i-1] += 1
      digit[-i] = -1
    elif digit[-i] < digit[-i-1] - 1:
      digit[-i] = -1
  for i in range(1, len_digit):
    if digit[i] == -1:
      for j in range(i, len_digit):
        digit[j] = max(digit[j-1] - 1, 0)
      break
  num = d[0]
  for d in digit[1:]:
    num = num * 10 + d
print(num)

Submission status: Runtime Error

Solution code:
from typing import List


def lunlun_maker(l: List[int]) -> List[int]:
    next_lunluns = []
    for e in l:
        nxt = e * 10
        mod = e % 10
        if 0 < mod < 9:
            next_lunluns.extend([nxt + mod - 1, nxt + mod, nxt + mod + 1])
        elif mod == 0:
            next_lunluns.extend([nxt, nxt + 1])
        elif mod == 9:
            next_lunluns.extend([nxt + 8, nxt + 9])
    return next_lunluns


def get_lunlun(num: int) -> int:
    lunluns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    counter = len(lunluns)
    counter_tmp = counter
    while counter < num:
        lunluns = lunlun_maker(lunluns)
        counter_tmp = counter
        counter += len(lunluns)
    return lunluns[num - counter_tmp - 1]


K = int(input())
print(get_lunlun(K))

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from collections import deque

def main():
    def gen():
        counter = 0
        q = deque(range(1, 10))
        while counter < 100001:
            n = q.popleft()
            yield n
            counter += 1
            t = n % 10
            if t > 0:
                q.append(n*10 + (t - 1))
            q.append(n*10 + t)
            if t < 9:
                q.append(n*10 + (t + 1))
    g = gen()
    for _ in range(ii() - 1):
        next(g)
    print(next(g))

main()

Submission status: Runtime Error

Solution code:
def main():
    kk = int(input())
#    k = map(int,input())
    def fun(k):
        k_list = []
        k_list.append(k%10)
        p = 10
        while int(k/p)>0:
            k_list.append(int(k/p))
            p *=10
        update = 0
        for i in range(len(k_list)):
            if i == len(k_list)-1:
                if k_list[i] == 9:
                    k_list.append(1)
                    k_list[i] = 0
                    
                else:
                    k_list[i]+=1
                update +=1
            else:
                if k_list[i+1] == 9:
                    if k_list[i+1] > k_list[i]:
                        k_list[i] += 1
                        update+=1                        
                elif k_list[i+1] <9:
                    if k_list[i+1] >= k_list[i]:
                        k_list[i] += 1
                        update+=1 
                    else:
                        k_list[i+1] +=1
                        k_list[i] -=1
                        update+=1 
            if update == 1:
                break
        result = 0
        p = 1
        for ii in k_list:
            result += ii * p
            p *=10
        return(result)
        
    K = 0
    for i in range(kk):
        K = fun(K)
    print (K)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    kk = int(input())
#    k = map(int,input())
    def fun(k):
        k_list = []
        k_list.append(k%10)
        p = 10
        while int(k/p)>0:
            k_list.append(int(k/p))
            p *=10
        update = 0
        for i in range(len(k_list)):
            if i == len(k_list)-1:
                if k_list[i] == 9:
                    k_list.append(1)
                    k_list[i] = 0
                    
                else:
                    k_list[i]+=1
                update +=1
            else:
                if k_list[i+1] == 9:
                    if k_list[i+1] > k_list[i]:
                        k_list[i] += 1
                        update+=1                        
                elif k_list[i+1] <9:
                    if k_list[i+1] >= k_list[i]:
                        k_list[i] += 1
                        update+=1 
                    else:
                        k_list[i+1] +=1
                        k_list[i] -=1
                        update+=1 
            if update == 1:
                break
        result = 0
        p = 1
        for ii in k_list:
            result += ii * p
            p *=10
        return(result)
        
    K = 0
    for i in range(kk-1):
        K = fun(K)
    print (K)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
K = int(input())

k = 0
nums = [n for n in range(1, 10)]
while K != k:
    num = nums.pop(0)
    last1 = int(str_num[len(str(num)) - 1])
    if last1== 0:
        append_num = [int(str_num + str(n)) for n in [0, 1]]
    elif last1 == 9:
        append_num = [int(str_num + str(n)) for n in [8, 9]]
    else:
        append_num = [int(str_num + str(n)) for n in range(last1 - 1, last1 + 2)]
    nums += append_num
    k += 1
else:
    print(num)

Submission status: Runtime Error

Solution code:
import heapq
k = int(input())
run_list = [i for i in range(1,10)]
heapq.heapify(run_list)
result = 0
for i in range(k):
  result = heapq.pop(run_list)
  if result % 10 ==0:
    new_1 = result * 10
    new_2 = result * 10 + 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  elif result % 10 ==9:
    new_1 = result * 10 + 8
    new_2 = result * 10 + 9
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  else:
    new_1 = result * 10 + (resut % 10)
    new_2 = result * 10 + (resut % 10) + 1
    new_3 = result * 10 + (resut % 10) - 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
print(result)
    heapq.heappush(run_list, new_3)

Submission status: Runtime Error

Solution code:
from collections import deque

def main():
  	K = int(input())
    que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])

    while K:
        if K == 1:
            ans = que.popleft()
            break
        K -= 1
        v = que.popleft()
        if v[-1] == '0':
            que.append(v + '0')
            que.append(v + '1')
        elif v[-1] == '9':
            que.append(v + '8')
            que.append(v + '9')
        else:
            que.append(v + str(int(v[-1]) - 1))
            que.append(v + str(int(v[-1])))
            que.append(v + str(int(v[-1]) + 1))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に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()))

# 2次元リスト化
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:  # 1桁の数はすべてlun_lun
    print(K)
else:  # 桁数の小さいものからlun_lun数を生成し，queueに加えていく
    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)

Submission status: Runtime Error

Solution code:
K = int(input())
cand = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
for _ in range(4):
    tmp = []
    for v in cand[-1]:
        if v%10 != 0:
            tmp.append(v*10 + (v%10-1))
        tmp.append(v*10 + (v%10))
        if v%10 != 9:
            tmp.append(v*10 + (v%10+1))
    cand.append(tmp)
ans = []
for i in range(len(cand)):
    for v in cand[i]:
        ans.append(v)
ans = sorted(ans)
print(ans[K-1])

Submission status: Runtime Error

Solution code:
K = input()
from collections import deque

a = deque()

for i in range(1,10):
    a.append(i)
    
for i in range(K):
    j = a.popleft()
    if j%10 != 0:
        a.append((10*j) + ((j%10) -1))
        
    a.append((10*j)+j%10)
    
    if j%10 != 9:
        a.append((10*j) +((j%10)+1))
        
a.popleft()

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
def f(k):
    def lunlun(n):
        s = [int(i) for i in str(n)]
        for i in range(len(s) - 1):
            if abs(s[i] - s[i + 1]) > 1:
                return False
        return True
    cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
    for i, begin in enumerate(cum_npi):
        if k < begin:
            begin = cum_npi[i-1]
            break
    print(f"begin = {begin}")
    found = begin
    while found != k:
        begin += 1
        if lunlun(begin):
            found += 1
            if found == k:
                break
    print(begin)

f(int(input()))

Submission status: Runtime Error

Solution code:
def f(k):
    def lunlun(n):
        s = [int(i) for i in str(n)]
        for i in range(len(s) - 1):
            if abs(s[i] - s[i + 1]) > 1:
                return False
        return True
    i = 0
    while k > 0:
        i += 1
        if lunlun(i):
            k -= 1
    print(i)

f(int(input())

Submission status: Runtime Error

Solution code:
K=int(input())
Q=queue.Queue()
for a in range(1,10):
    Q.put(a)
for a in range(K-1):
    now=Q.get()
    for b in range(-1,2):
        add=(now%10)+b
        if add>=0 and add<=9:
            Q.put(now*10+add)
print(Q.get())

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

queue = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(n):
    x = queue[i]
    if x % 10 != 0:
        queue.append(10 * x + x % 10 - 1)
    queue.append(10 * x + x % 10)
    if x % 10 != 9:
        queue.append(10 * x + x % 10 + 1)

print(x)

Submission status: Runtime Error

Solution code:
from collections import deque

k = int(input())

q = deque()

if k > 9:
    for i in range(1, 10):
        q.append(i)

for _ in range(k):
    temp = q.popleft()
    if temp % 10 != 0:
        q.append(temp*10+int(str(temp)[-1])-1)
    
    q.append(temp*10+int(str(temp)[-1]))

    if temp % 10 != 9:
        q.append(temp*10+int(str(temp)[-1])+1)

print(temp)

Submission status: Runtime Error

Solution code:
n = int(input())

queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for _ in range(n):
    x = euque.pop(0)
    if x % 10 != 0:
        queue.append(10 * x - 1)
    queue.append(10 * x)
    if x % 10 != 9:
        queue.append(10 * x + 1)

print(x)

Submission status: Runtime Error

Solution code:
k = int(input())
lunlun = [1,2,3,4,5,6,7,8,9]
i = 0
while len(lunlun) < k:
  p = lunlun[i]
  if str(p)[-1] == 0:
    lunlun.append(int(str(p)+'0'))
    lunlun.append(int(str(p)+'1'))
  elif str(p)[-1] == 9:
    lunlun.append(int(str(p)+'8'))
    lunlun.append(int(str(p)+'9'))
  else:
    lunlun.append(int(str(p)+str(int(str(p)[-1])-1)))
    lunlun.append(int(str(p)+str(int(str(p)[-1]))))
    lunlun.append(int(str(p)+str(int(str(p)[-1])+1)))
  i += 1

print(lunlun[k-1])

Submission status: Runtime Error

Solution code:
from queue import deque
k=input()
que=deque([i for i in range(1,10)])
for i in range(k):
    x=que.popleft()
    if x%10!=0:
        que.append(10*x+x%10-1)
    que.append(10*x+x%10)
    if que%10!=9:
        que.append(10*x+q%10+1)
print(x)

Submission status: Runtime Error

Solution code:
from queue imort deque
k=input()
que=deque([i for i in range(1,10)])
for i in range(k):
    x=que.popleft()
    if x%10!=0:
        que.append(10*x+x%10-1)
    que.append(10*x+x%10)
    if que%10!=9:
        que.append(10*x+q%10+1)
print(x)

Submission status: Runtime Error

Solution code:
import numpy as np
K = input()
lunlun_number = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
for _ in range(9):
    tmp = []
    for n in lunlun_number[-1]:
        if n % 10 != 0:  # 末尾が0の場合は-1した数がルンルン数にならないのでそれ以外を採用
            tmp.append(n * 10 + (n % 10 - 1))
        tmp.append(n * 10 + (n % 10))
        if n % 10 != 9:  # 末尾が9のときは+1した数がルンルン数にならないのでそれ以外を採用
            tmp.append(n * 10 + (n % 10 + 1))
    lunlun_number.append(tmp)
lunlun_number = np.array(lunlun_number).flatten()
print(lunlun_number[K - 1])

Submission status: Runtime Error

Solution code:
a=[]

def dfs(x):
  if x>3234566667:
    return
  a.append(x)
  for i in range(10):
    if abs(x%10-i) <= 1:
      dfs(x%10+i)
      
for i in range(1,10):
  dfs(i)
a =sorted(a)
k=int(input())
print(a[k-1])

Submission status: Runtime Error

Solution code:
from collections import deque

k = int(input())
lunlun = []
q = deque([1,2,3,4,5,6,7,8,9])
for i in range(k-1):
    first = q.popleft()
    if first%10-1 >= 0:
        q.append(first*10 + (first%10-1))
    q.append(first*10 + first%10)
    if first%10+1 <= 9:
        q.append(10*first + (first%10+1))
    print(q)
print(q[0])

Submission status: Runtime Error

Solution code:
k=int(input())
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        if z==0:
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        elif 1<=z<=8:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        else:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print(v[k-(d-l)-1])

Submission status: Runtime Error

Solution code:
n = int(input())
lunlun = [[1,2,3,4,5,6,7,8,9]]

for _ in range(2):
    tmp = []
    for i in lunlun[-1]:
        if i % 10 == 0 :
            tmp.append(10 * i + i % 10)
            tmp.append(10 * i + i % 10 + 1)
        elif i % 10 == 9:
            tmp.append(10 * i + i % 10 - 1)
            tmp.append(10 * i + i % 10)
        else:
            tmp.append(10 * i + i % 10 - 1)
            tmp.append(10 * i + i % 10)
            tmp.append(10 * i + i % 10 + 1)
    lunlun.append(tmp)
ans = []
for i in lunlun:
    for j in i:
        ans.append(j)
print(ans[n-1])

Submission status: Runtime Error

Solution code:
k = int(input())
a = [i for i in range(1, 10)]
while True:z
    if k <= len(a):
        print(a[k-1])
        exit()
    k -= len(a)
    old = []
    old, a = a, old
    for i in range(len(old)):
        for j in range(-1, 2):
            d = old[i]%10+j
            if d >= 0 and d <= 9:
                a.append(old[i]*10+d)

Submission status: Runtime Error

Solution code:
k = int(input())

d = deque(list(range(1, 10)))
c = 0
v = 0
while c < k:
    v = d.popleft()
    c += 1
    if v % 10 == 9:
        d.append(v * 10 + 8)
        d.append(v * 10 + 9)
    elif v % 10 == 0:
        d.append(v * 10)
        d.append(v * 10 + 1)
    else:
        t = v % 10
        d.append(v * 10 + t - 1)
        d.append(v * 10 + t)
        d.append(v * 10 + t + 1)
print(v)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin >> k;
  vector<unsigned long long> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  int i = 0;
  while (vec.size() < k) {
    if (vec.at(i) % 10 == 0) {
      unsigned long long x = vec.at(i)*10;
      vec.push_back(x);
      vec.push_back(x+1);
    }
    else if (vec.at(i) % 10 == 9) {
      unsigned long long y = vec.at(i)*10 + vec.at(i)%10;
      vec.push_back(y-1);
      vec.push_back(y);
    }
    else {
      unsigned long long z = vec.at(i)*10 + vec.at(i)%10;
      vec.push_back(z-1);
      vec.push_back(z);
      vec.push_back(z+1);
    }
    i++;
  }
  cout << vec.at(k-1) << endl;
}

Submission status: Runtime Error

Solution code:
k = int(input())
anss = [1,2,3,4,5,6,7,8,9]
for i in range(12):
    if len(anss) > k:
        print(new_anss[k-1])
        break
    new_anss = []
    for ans in anss:
        if ans % 10 != 0:
            new_anss += [ans*10+ans%10-1]
        new_anss += [ans*10+ans%10]
        if ans % 10 != 9:
            new_anss += [ans*10+ans%10+1]
    k -= len(anss)
    anss = new_anss

Submission status: Runtime Error

Solution code:
k = int(input())
anss = [1,2,3,4,5,6,7,8,9]
for i in range(12):
    if len(anss) > k:
        print(new_anss[k-1])
        break
    new_anss = []
    for ans in anss:
        if ans % 10 != 0:
            new_anss += [ans*10+ans-1]
        new_anss += [ans*10+ans]
        if ans % 10 != 9:
            new_anss += [ans*10+ans+1]
    k -= len(anss)
    anss = new_anss

Submission status: Runtime Error

Solution code:
from collections import deque
K = int(input()) - 1
todo = deque(range(1, 10))
ans = []
counter = 0
while counter <= K:
    seed = todo.pop(0)
    ans.append(seed)
    counter += 1
    last_dig = int(str(seed)[-1])
    for i in range(max(0, last_dig-1), min(10, last_dig+2)):
        todo.append(int(str(seed) + str(i)))
print(ans[-1])

Submission status: Runtime Error

Solution code:
k = int(input())
old = [1,2,3,4,5,6,7,8,9]
new = []
count = 9
if k <= count:
    print(ans[k])
while count < k:
    if len(old) > 0:
        i = old.pop(0)
        last = i%10
        if last != 0:
            new.append(i*10 + (last-1))
            count += 1
            if count == k:
                break
        new.append(i*10 + last)
        count += 1
        if count == k:
            break
        if last != 9:
            new.append(i*10 + (last+1))
            count += 1
            if count == k:
                break
    else:
        old = new
        new = []
print(new[-1])

Submission status: Runtime Error

Solution code:
def main():
    kk = int(input())
#    k = map(int,input())
    def fun(k):
        k_list = []
        k_list.append(k%10)
        p = 10
        while int(k/p)>0:
            k_list.append(int(k/p))
            p *=10
        for i in range(len(k_list)):
            if i == len(k_list)-1:
                if k_list[i] == 9:
                    k_list.append(1)
                    for j in range(i+1):
                        k_list[j] = 0
                    break
                else:
                    k_list[i] +=1
                break
            elif k_list[i] - k_list[i+1] <=0:
                 if k_list[i] == 9:
                     continue
                 else:
                     k_list[i] +=1
                 break
        result = 0
        p = 1
        for ii in k_list:
            result += ii * p
            p *=10
        return(result)
    K = 0
    for i in range(kk-1):
        K = fun(K)
    print (K)

if __name__ == '__main__':
    main()