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:
from collections import deque
que=deque([range(1,10)])
k=int(input())
count=0
while count!=k:
  a=que.popleft
  count+=1
  if a%10 == 1:
    que.append([10*a+1,10*a+2])
  elif a%10==9:
    que.append([10*a+8,10*a+9])
  else:
    b=a*10+(a%10)-1
    que.append([b,b+1,b+2])
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque
que=deque([range(1,10)])
k=int(input())
count=0
while count!=k:
  a=que.popleft
  count+=1
  if a%10 == 1:
    que.append([10*a+1,10*a+2])
  elif a%10==9:
    que.append([10*a+8,10*a+9])
  else:
    b=a*10+(a%10)-1
    que.append([b,b+1,b+2])
print(count)

Submission status: Runtime Error

Solution code:
def rn(x):
    z = list(map(int,list(str(x))))
    N = len(z)
    z.insert(0,0)
    dp = [[[0 for _ in range(10)] for _ in range(2)] for _ in range(N+1)]
    dp[1][0][z[1]]=1
    for j in range(z[1]):
        cp[1][1][j]=1
    for i in range(2,N+1):
        if abs(z[i]-z[i-1])<=1:
            dp[i][0][z[i]] = 1
        for j in range(10):
            dp[i][1][j] = dp[i-1][0][z[i-1]]*int(j<z[i])*int(abs(j-z[i-1])<=1)
            for k in range(10):
                dp[i][1][j] += dp[i-1][1][k]*int(abs(j-k)<=1)
    cnt = dp[N][0][z[N]]
    for j in range(10):
        cnt += dp[N][1][j]
    return cnt
K = int(input())
high = 3234566667
low = 0
while high-low>1:
    mid = (high+low)//2
    if rn(mid)>=K:
        high = mid
    else:
        low = mid
print(high)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(500000)
K = int(input())

ans_list = []
def dfs(A):
    if len(A)!=0 and int("".join(A))<=10**6:
        ans_list.append(int("".join(A)))
    elif len(A)!=0 and int("".join(A))>10**6:
        return
    if len(A)==0:
        for i in range(1, 10, 1):
            A.append(str(i))
            dfs(A)
            A.pop()
        return

    for i in range(0, 10, 1):
        if abs(int(A[-1])-i)<=1:
            A.append(str(i))
            dfs(A)
            A.pop()
    return
dfs([])
ans_list.sort()
print(ans_list[K-1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(500000)
K = int(input())

ans_list = []
def dfs(A):
    if len(A)!=0 and int("".join(A))<=10**5:
        ans_list.append(int("".join(A)))
    elif len(A)!=0 and int("".join(A))>10**5:
        return
    if len(A)==0:
        for i in range(1, 10, 1):
            A.append(str(i))
            dfs(A)
            A.pop()
        return

    for i in range(0, 10, 1):
        if abs(int(A[-1])-i)<=1:
            A.append(str(i))
            dfs(A)
            A.pop()
    return
dfs([])
ans_list.sort()
print(ans_list[K-1])

Submission status: Runtime Error

Solution code:
K = int(input())

ans_list = []
def dfs(A):
    if len(A)!=0 and int("".join(A))<=10**5:
        ans_list.append(int("".join(A)))
    elif len(A)!=0 and int("".join(A))>10**5:
        return
    if len(A)==0:
        for i in range(1, 10, 1):
            A.append(str(i))
            dfs(A)
            A.pop()
        return

    for i in range(0, 10, 1):
        if abs(int(A[-1])-i)<=1:
            A.append(str(i))
            dfs(A)
            A.pop()
    return
dfs([])
ans_list.sort()
print(ans_list[K-1])

Submission status: Runtime Error

Solution code:
from collections import deque

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

for i in range(k-1):
    # popを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)

Submission status: Runtime Error

Solution code:
K=int(input())
nums=[i for i in range(1,10)]
for i in range(K):
    a=nums.pop(0)
    if a%10!=0:
        nums.append(a*10 + %10 - 1)
    
    nums.append(a*10 + a%10)
    
    if a%10!=9:
        nums.append(a*10 + a%10 + 1)

print(a)

Submission status: Runtime Error

Solution code:
K=int(input())
ANS=[]
for i in range(1,10**6):
  LEN=len(str(i))
  STR=str(i)
  if LEN==1:
    ANS+=[i]
  for k in range(LEN-1):
    if abs(int(STR[k])-int(STR[k+1]))>1:
      break
    if k==LEN-2:
      ANS+=[i]
ans=ANS[K-1] 
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
R=[["1","2","3","4","5","6","7","8","9"]]
count=9
for i in range(N):
  if count>=N:
    break
  else:
    temp=[]
    for r in R[i]:
      if r[-1]=="9":
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
      elif r[-1]=="0":
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
      else:
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
    R.append(temp)
    count+=len(temp)
N=N-(count-len(temp))
print(R[-1][N-1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**10)

k = int(input())
l = len(str(k))+4
A = [str(i+1) for i in range(9)]
B = ["0"] + A
ans = []
#print(l)

def dfs(num,l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        ans.append(int(num))
        for i in B:
            if abs(int(num[-1])-int(i)) < 2:
                dfs(num + i,l)
if k <= 9:
    print(k)
else:
    for i in A:
        dfs(i,l)
    ans = sorted(ans)
    #print(ans)
    print(ans[k-1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

k = int(input())
l = len(str(k))+4
A = [str(i+1) for i in range(9)]
B = ["0"] + A
ans = []
#print(l)

def dfs(num,l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        ans.append(int(num))
        for i in B:
            if abs(int(num[-1])-int(i)) < 2:
                dfs(num + i,l)
if k <= 9:
    print(k)
else:
    for i in A:
        dfs(i,l)
    ans = sorted(ans)
    #print(ans)
    print(ans[k-1])

Submission status: Runtime Error

Solution code:
k = int(input())
l = len(str(k))
A = [str(i) for i in range(10)]
ans = [i+1 for i in range(9)]

def dfs(num,l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        for i in A:
            if abs(int(num[-1])-int(i)) < 2:
                dfs(num + i,l)
for i in A:
    dfs(i,l)
ans = sorted(ans)
#print(ans)
print(ans[k+1])

Submission status: Runtime Error

Solution code:
ans=0
runrun = 0
i =0
while runrun = K:
    if i < 10:
        runrun +=1
    else:
        a = list(map(int,str(i)))
        for j in range(1,len(a)):
            tmp = 0
            if abs(a[j]-a[j-1])<=1:
                tmp +=1
        if tmp == len(a)-1:
            runrun +=1
            ans = i
    i +=1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())
table = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
c = 9
result = []
for i in table:
  runrun = i
  if runrun[-1] == '0':
    table.extend([runrun + str(int(runrun[-1])), 
                   runrun + str(int(runrun[-1])+1)])
    c += 2
  elif runrun[-1] == '9':
    table.extend([runrun + str(int(runrun[-1])-1), 
                   runrun + str(int(runrun[-1]))])
    c += 2
  else:
    table.extend([runrun + str(int(runrun[-1])-1), 
                   runrun + str(int(runrun[-1])), 
                   runrun + str(int(runrun[-1])+1)])
    c += 3
  if c>=K:
    print(table[K-1])
    exit()

Submission status: Runtime Error

Solution code:
K = int(input())

def lunlun(x):
    x = str(x)
    if all((abs(int(x[i])-int(x[i+1]))<=1) for i in range(len(x)-1)):
        return True
    else:
        return False

def countLunlun(counter, i, K):

    if lunlun(i):
        counter += 1

    if counter == K:
        print(i)
    else:
        countLunlun(counter, i+1, K)

countLunlun(0,1,K)

Submission status: Runtime Error

Solution code:
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
B=[]
C=[]
D=[]
E=[]
F=[]
G=[]
H=[]
I=[]

def henkan(A):
    a=len(A)
    B=[]
    for i in range(a):
        if A[i]%10==0:
            B.append(10*A[i])
            B.append(10*A[i]+1)
        elif A[i]%10==9:
            B.append(10*A[i]+9)
            B.append(10*A[i]+8)
        else:
            x=A[i]%10
            B.append(10*A[i]+x)
            B.append(10*A[i]+x+1)
            B.append(10*A[i]+x-1)
    return B

B=henkan(A)
C=henkan(B)
D=henkan(C)
E=henkan(D)
F=henkan(E)
G=henkan(F)
H=henkan(G)
I=henkan(H)
ans=A+B+C+D+E+F+G+H+I
ans=sorted(ans)

print(ans[K-1])

Submission status: Runtime Error

Solution code:
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
B=[]
C=[]
D=[]
E=[]
F=[]
G=[]
H=[]
I=[]

def henkan(A):
    a=len(A)
    B=[]
    for i in range(a):
        if A[i]==0:
            B.append(10*A[i])
            B.append(10*A[i]+1)
        elif A[i]==9:
            B.append(10*A[i]+9)
            B.append(10*A[i]+8)
        else:
            x=A[i]%10
            B.append(10*A[i]+x)
            B.append(10*A[i]+x+1)
            B.append(10*A[i]+x-1)
    return B

B=henkan(A)
C=henkan(B)
D=henkan(C)
E=henkan(D)
F=henkan(E)
G=henkan(F)
H=henkan(G)
I=henkan(H)
ans=A+B+C+D+E+F+G+H+I
ans=sorted(ans)

print(ans[K-1])

Submission status: Runtime Error

Solution code:
cur = []

def recur(n):
    if n > 10 ** 9:
        return
    cur.append(n)
    for i in range(10):
        if abs(n % 10 - i) <= 1:
            recur(10 * n + i)

for i in range(1, 10):
    recur(i)
cur.sort()
n = int(input())
print((cur[n - 1]))

Submission status: Runtime Error

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():

    K = int(input())
    q = deque()
    for i in range(1, 10):
        q.append(i)
    cnt = 9
    while cnt < K:
        x = q.popleft()
        d = x % 10
        for v in [d-1, d, d+1]:
            if 0 <= v <= 9:
                y = x*10 + v
                q.append(y)
                cnt += 1
    print(y)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
k = int(input())

r_num = list(range(1,10))
for i in range(3):
    for j in range(len(r_num)):
        for m in range(10):
            if abs(r_num[j]%10-m) <= 1:
                new = r_num[j] * 10 + m
                r_num.append(new)
print(r_num[k-1])

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

K = int(input())

LLs = []

def dfs(d, num):
    LLs.append(num)
    
    if d == 10: return

    a = num % 10
    for i in [-1, 0, 1]:
        b = a + i
        if  0 <= b < 10:
            dfs(d+1, num * 10 + b)

d = 1
for i in range(1, 10):
    dfs(d, i)

print(sorted(LLs)[K-1])

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

K = int(input())

d = 10000

LLs = []

def dfs(d, num):
    LLs.append(num)
    
    if d == 10: return

    a = num % 10
    for i in [-1, 0, 1]:
        b = a + i
        if  0 <= b < 10:
            dfs(d+1, num * 10 + b)

d = 1
for i in range(1, 10):
    dfs(d, i)

print(sorted(LLs)[K-1])

Submission status: Runtime Error

Solution code:
import sys
K = int(input())

listup = []
listup.append(list(range(1, 10)))
list_length = 9
finish = False
for i in range(10000000):
    new_list_floor = []
    for value in listup[i]:
        newlist = []
        mod_value = value % 10
        if mod_value == 0:
            newlist.append(value * 10 + mod_value)
            newlist.append(value * 10 + mod_value + 1)
        elif mod_value == 9:
            newlist.append(value * 10 + mod_value - 1)
            newlist.append(value * 10 + mod_value)
        else:
            newlist.append(value * 10 + mod_value - 1)
            newlist.append(value * 10 + mod_value)
            newlist.append(value * 10 + mod_value + 1)
        list_length_before = list_length
        list_length += len(newlist)
        new_list_floor.extend(newlist)
        if list_length >= K:
            diff = K - list_length_before
            print(newlist[diff - 1])
            sys.exit(0)
    listup.append(new_list_floor)
print(listup)

Submission status: Runtime Error

Solution code:
rom collections import deque
 
K = int(input())
que = deque([i for i in range(1, 10)])
lunlun = []
 
while que:
    num = que.pop()
    lunlun.append(num)
    for i in range(10):
        if abs(int(str(num)[-1]) - i) <= 1:
            cand = int(str(num) + str(i))
            if cand < 10000000000:
                que.append(cand)
 
lunlun.sort()
print(sorted(lunlun)[K - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k=int(input())
cand=[[1,2,3,4,5,6,7,8,9]]
for _ in range(9): #上記の操作を9回繰り返せば10^5個以上のルンルン数を列挙できる
  tmp=[]
  for val in cand[-1]:
    if val%10!=0: #末尾が0のときは(末尾-1)を付け加えた数はルンルン数にならない
      tmp.append(val*10+(val%10-1))
    tmp.append(val*10+(val%10))
    if val%10!=9: #末尾が9のときは(末尾+1)を付け加えた数はルンルン数にならない
      tmp.append(val*10+(val%10+1))
cand.append(tmp)
ans=[]
for i in range(len(cand)):
  for val in cand[i]:
    ans.append(val)

print(ans[k-1])

Submission status: Runtime Error

Solution code:
k = int(input())
#n, k = list(map(int, input().split()))
#a = list(map(int, input().split()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k):
    x = q.popleft()
    a = 10*x+(x % 10)
    if x % 10 != 0:
        q.append(a-1)
    q.append(a)
    if x % 10 != 9:
        q.append(a+1)

print(x)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
cnt = 0

if n<10:
    print(n)
else:
    cnt = 9
    isLunLun = 1
    i = 10
    while i<3234566667:
        digit_list = list(map(int,list(str(i))))
        for j in range(0,len(digit_list)-1):
            if digit_list[j] - digit_list[j+1] <1:
                isLunLun = 0
                i += math.pow(10,len(digit_list)-1-j)
                break
            if digit_list[j+1] - digit_list[j] >1
                i += math.pow(10,len(digit_list)-2-j)
                break
        if isLunLun == 1:
            cnt += 1
            i += 1
        isLunLun = 1
        if cnt == n:
            print(i)
            break

Submission status: Runtime Error

Solution code:
n=int(input())
q=[1,2,3,4,5,,6,7,8,9]
for i in range(n):
  a=q.pop(0)
  if a%10==0:
    q.append(a*10)
    q.append(a*10+1)
  elif a%10==9:
    q.append(a*10-1)
    q.append(a*10)
  else:
    q.append(a*10-1)
    q.append(a*10)
    q.append(a*10+1)
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x, k = map(int, input().split())

n = x%k

if n < abs(n-k):
  print(n)
else:
  print(abs(n-k))

Submission status: Runtime Error

Solution code:
K=int(input())
a=0
i=0
while i<K:
    u=0
    a+=1
    s=str(a)
    for j in range(len(s)-1):
        if abs(int(s[j])-int(s[j+1]))>1:
            u=1
            break
    if u==0
        i+=1
print(a)

Submission status: Runtime Error

Solution code:
K = int(input())
if K < 13:
    print(K)
    quit()

now = [*range(1, 10)]

count = 9
while True:
    nxt = []
    for l in now:
        tail = l % 10
        for t in range(max(0, tail - 1), min(10, tail + 2)):
            nxt.append(l * 10 + t)
            count += 1
            if count == K:
                print(l * 10 + t)
                quit()
    now = nxt

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())

def fun(k):
    lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    index = 0
    while True:
        if len(lun_luns) >= k:
            break
        num = lun_luns[index]
        mod = num%10
        if mod == 9:
            lun_luns.extend([n+mod-1, n+mod])
        elif mod == 0:
            lun_luns.extend([n, n+1])
        else:
            lun_luns.extend([n+mod-1, n, n+mod+1])
        index += 1
    
    return lun_luns

print(fun(k)[k-1])

Submission status: Runtime Error

Solution code:
k = int(input())
li = []


def runruncheck(num):
    num_str = str(num)
    num_array = list(map(int, num_str))
    flag = True

    for j in range(len(num_str) - 1):
        if abs(num_array[j] - num_array[j + 1]) > 1:
            flag = False

    return flag


for i in range(1, 10 ** 6):
    if runruncheck(i):
        li.append(i)

print(li[k-1])

Submission status: Runtime Error

Solution code:
K=int(input())
A=[x for x in range(K*10000)]
B=[]
inLoop=True
for x in A:
    z=str(x)
    n=len(z)
    if n==1:
        B.append(x)
    else:       
        while inLoop:
            for i in range(n-1):
                y=int(z[i])-int(z[i+1])
                if abs(y)>1:
                    inLoop=False
            B.append(x)
            inLoop=False
    
        if len(B)==K+1:
            break
print(B[K])

Submission status: Runtime Error

Solution code:
k = int(input())
array = []
for i in range(1, 100000 + 1):
  s = str(i)
  try:
    a = abs(int(s[0]) - int(s[1]))
    if a < 2:
      try:
        b = abs(int(s[1]) - int(s[2]))
        if b < 2:
          try:
            c = abs(int(s[2]) - int(s[3]))
            if c < 2:
              try:
                d = abs(int(s[3]) - int(s[4]))
                if d < 2:
                  try:
                    e = abs(int(s[4]) - int(s[5]))
                    if e < 2:
                      array.append(int(i))
                  except IndexError:
                    array.append(int(i))  
              except IndexError:
                array.append(int(i)) 
          except IndexError:
            array.append(int(i))
      except IndexError:
        array.append(int(i))
  except IndexError:
    array.append(int(i))
print(array[k - 1])

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for _ in range(n)]
count = []
max_list = []

for item in s:
    count_i = s.count(item)
    count.append(count_i)

for i in range(n):
    if count[i] == max(count) and not (s[i] in max_list):
        max_list.append(s[i])

max_list = sorted(max_list)
for item in max_list:
    print(item)

Submission status: Runtime Error

Solution code:
k = int(input())
que = []
for i in range(1,10):
  que.append(i)
ct = 0
while(len(que) < k):
  ct += 1
  value = que[0]
  que.remove(value)
  for i in [-1,0,1]:
    if 0 <= (value%10) + i and (value%10) + i <= 9:
      tmp = 10*value + (value%10) + i
      q.append(tmp)  
print(que[k-1-ct])

Submission status: Runtime Error

Solution code:
k = int(input())
que = []
for i in range(10):
  que.append(i)
while(len(que) < k-1):
  x = que[0]
  que.remove(x)
  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(que[k-1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(str, (range(1, 10))))
total = a[:]
cnt = 9
while cnt < n:
    new = []
    for i in a:
        if i[-1] == "0":
            new = [(i + "0"), (i + "1")]
            cnt += 2
            if cnt >= n:
                break
        elif i[-1] == "9":
            new = [(i + "8"), (i + "9")]
            cnt += 2
            if cnt >= n:
                break
        else:
            new.append(i + str(int(i[-1]) -1))
            new.append(i + str(int(i[-1])))
            new.append(i + str(int(i[-1]) + 1))
            cnt += 3
            if cnt >= n:
                break
    total += new[:]
    a = new[:]
                
print(total[n-1])

Submission status: Runtime Error

Solution code:
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():
    K = int(input())
    if 0<=K<=10:
        print(K)
        exit()

    lunlun = [i for i in range(1,10)]
    m = 0

    while len(lunlun) < K:
        x = lunlun[m]
        btm = x % 10

        if btm - 1 >= 0:
            lunlun.append(10*x+btm-1)

        lunlun.append(10*x+btm)

        if btm + 1 < 10:
            lunlun.append(10*x+btm+1)

        m += 1

    print(lunlun[::-1][len(lunlun)-K])

if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
k = int(input())
lunlun = [0] * 100
lunlun[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 1

for i in range(9):
    n = len(lunlun[i])
    lunlun[i+1] = []
    for x in lunlun[i]:
        r = x%10
        if r > 0:
            lunlun[i+1].append(10*x + r-1)
        lunlun[i+1].append(10*x + r)
        if r < 9:
            lunlun[i+1].append(10*x + r+1)
    i += 1

for i in range(1, 11):
    for j in range(len(lunlun[i])):
        k -= 1
        if k == 0:
            print(lunlun[i][j])
            exit()

Submission status: Runtime Error

Solution code:
a = int(input())

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

For  x  in  range(a):
  tmp = N[x]
  if tmp%10 != 0:
    N.append(tmp*10+tmp%10-1)
  N.append(tmp*10+tmp%10)
  if tmp%10 != 9:
    N.append(tmp*10+tmp%10+1)
print(N[a-1])

Submission status: Runtime Error

Solution code:
K=int(input())

from collections import deque
num=deque()
for i in range(1,10):
  num.append(i)

for j in range(K):
  l=num.popleft()
  if ans%10 !=0:
    num.append(l*10+(l%10-1))
  num.append(l*10)
  if ans%10 != 9:
    num.append(l*10+(l%10+1))

print(l)

Submission status: Runtime Error

Solution code:
from collections import deque


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

for i in range(k):
  a = q.popleft()
  if a % 10 == 1:
    q.append([10*a, 10*a+1])
  elif a % 10 == 9:
    q.append([10*a + 8, 10*a + 9])
  else:
    q.append([10*a + a - 1, 10*a + a, 10*a + a + 1])
else:
  print(a)

Submission status: Runtime Error

Solution code:
k=int(input())
a=[i for i in range(10)]

while True:
    #るんるん数の候補を、桁数ごとに積み上げます。まず１桁
    if k<=len(a):
        print(a[k-1])
        break
    """
    1桁に成果がなければ、kから１桁のlen(るんるん数リスト)を引いて、
    ２桁のリストを作ります。作り方は、元のるんるんリストのそれぞれの数を１０倍して、
    その１０の位と同じか隣接する値を加えたものをappend.
    以下同様
    """
    k-=len(a)
    old=[]
    old, a=a, old
    for x in old:
        for i in range(-1,2):
            d=x%10+d
            if d<0 or d>9:
                continue
            new_x=x*10+d
            a.append(new_x)

Submission status: Runtime Error

Solution code:
K = int(input())

if K < 10:
  print(K)
else:
  count = 9

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

while count != K:
  for x in queue:
    if x%10 != 0:
      queue.append(10*x + (x%10) - 1)
      count += 1
      if count == K:
        break

    queue.append(10*x + (x%10))
    count += 1
    if count == K:
      break

    if x%10 != 9:
      queue.append(10*x + (x%10) + 1)
      count += 1
      if count == K:
        break

print(queue[-1])

Submission status: Runtime Error

Solution code:
k = int(input())
n = 0
i = 0
while True:
  i += 1
  i = str(i)
  i = "0" + i + "0"
  i_len = len(i) - 1
  flag = False
  for j in i_len:
    if abs(i[j+1] - i[j]) <= 1:
      continue
    else:
      break
      
    if j == (i_len - 1):
    	flag = True
        break
  
  if flag == True:
    n += 1
    flag = False
  
  if n == k:
    break
  
  i = int(i)

print(i)

Submission status: Runtime Error

Solution code:
k= int(input())
count= 0
num=1
if k<10:
    print(k)
else:
    while count != k:
        flag=0
        temp= str(num)
        numlist= list(temp)
        for i in range(0,len(numlist)-1):
            dis= int(numlist[i])-int(numlist[i+1])
            if abs(dis) >1:
                flag =1
                if i+1 > len(numlist)-1-2
                    num= num+ 10*(len(numlist)-(i+1))-1
                break
        if flag==0:
            count= count+1
        num= num+1
    print(num-1)

Submission status: Runtime Error

Solution code:
import math

N , K = map(int, input().split())
flag = "F"

lenN = int (math.log10(N) + 1)
lenK = int (math.log10(K) + 1)

N = abs(N-K*(10**abs(lenN-lenK+1)))
while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

Submission status: Runtime Error

Solution code:
K = int(input())
LL = [i for i in range(1,13)]  
def kth_ll(K):
    count = 12
    num = 12
    if K <= len(LL):
        return LL[K - 1]

    flag = 1
    while K > count:
        num += 1

        for i in str(num):
            if i != str(num)[-1]:
                if abs(str(num)[i] - str(num)[i + 1]) > 2:
                    flag = 0
                break
    return num


print(kth_ll(K))

Submission status: Runtime Error

Solution code:
LL = [i for i in range(1,13)]  
def kth_ll(K):
    count = 12
    num = 12
    if K <= len(LL):
        return LL[K - 1]

    flag = 1
    while K > count:
        num += 1

        for i in str(num):
            if i != str(num)[-1]
                if abs(str(num)[i] - str(num)[i + 1]) > 2:
                flag = 0
                break:
    return num

Submission status: Runtime Error

Solution code:
LL = [i for i in range(1,13)]  
def kth_ll(K):
  count = 12
  num = 12
  if K <= len(LL):
    return LL[K - 1]

  flag = 1
    while K > count:
      num += 1

      for i in str(num):
        if i != str(num)[-1]
          if abs(str(num)[i] - str(num)[i + 1]) > 2:
            flag = 0
            break:
  return num

Submission status: Runtime Error

Solution code:
import heapq
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(l)

def f(x):
    # xの最後の数値だけ取り出す
    min_x = int(list(str(x))[-1])
    if min_x == 0:
        yield int(x + "0")
        yield int(x + "1")
    elif min_x == 9:
        yield int(x + "8")
        yield int(x + "9")
    else:
        yield int(x + str(min_x - 1))
        yield int(x + str(min_x))
        yield int(x + str(min_x + 1))

K = int(input())
ans = 1
for i in range(K):
    if i == K - 1:
        ans = heapq.heappop(l)
        break
    for y in f(heapq.heappop(l)):
        heapq.push(l, y)
print(ans)

Submission status: Runtime Error

Solution code:
import heapq
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(l)

def f(x):
    # xの最後の数値だけ取り出す
    min_x = int(list(str(x))[-1])
    if min_x == 0:
        yield int(x + "0")
        yield int(x + "1")
    elif min_x == 9:
        yield int(x + "8")
        yield int(x + "9")
    else:
        yield int(x + str(min_x - 1))
        yield int(x + str(min_x)
        yield int(x + str(min_x + 1)))

K = int(input())
ans = 1
for i in range(K):
    if i == K - 1:
        ans = heapq.heappop(l)
        break
    for y in f(heapq.heappop(l)):
        heapq.push(l, y)
print(ans)