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


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


def f(k):
    if 1 <= k <= 9:
        print(k)
    else:
        nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
        cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
        for length, begin in enumerate(cum_npi):
            if k < begin:
                found = cum_npi[length - 1]
                break
        begin = 10 ** (length - 1)
        # length, begin, found
        k -= found
        x = [[]] * (length + 1)
        x[1] = list(range(1, 10))
        # x

        terminate = False
        i = 1
        while True:
            
            if len(x[i]): # len(x[i])
                digit = x[i][0]
                if i < length: 
                    i += 1
                    x[i] = nxt[digit].copy()
                    
                    
                    if i == length: 
                        while len(x[i]): # i, x[i]
                            k -= 1
                            
                            if k == 0:
                                x.pop(0)
                                #print("answer =", x)
                                ans = "".join([str(j.pop(0)) for j in x])
                                print(ans)
                                terminate = True
                                break
                            else:
                                x[i].pop(0)
                            
                        else:
                            
                            while len(x[i]) == 0:
                                i -= 1
                                x[i].pop(0)
                        if terminate:
                            break

f(int(input()))


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):
from collections import deque
K=int(input())
d=deque([_ for _ in range(1,10)])
if K<=9:
  print(K)
  exit()
i=0
while True:
  a=d.pop()
  i+=1
  if i==K:
    print(a)
    exit()
  if a%10!=0 and a%10!=9:
    d.extend([10*a+(a%10)+i for i in range(-1,2)])
  elif a%10==0:
     d.extend([10*a+i for i in range(2)])
  else:
     d.extend([10*a+i for i in range(-1,2)])

from collections import deque
K=int(input())
d=deque([_ for _ in range(1,10)])
if K<=9:
  print(K)
  exit()
i=0
while True:
  a=d.popleft()
  i+=1
  if i==K:
    print(a)
    exit()
  if a%10!=0 and a%10!=9:
    d.extend([10*a+(a%10)+i for i in range(-1,2)])
  elif a%10==0:
     d.extend([10*a+i for i in range(2)])
  elif a%10==9:
     d.extend([10*a+i for i in range(8,10)])

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())
import sys
sys.setrecursionlimit(1000000)
run = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def runrun(number):
    if len(number) < 16:
        last = int(number[-1])
        if last == 0:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
        elif last == 9:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])-1))
        else:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
            runrun(str(int(number[-1])-1))


for i in range(1, 10):
    runrun(str(i))
run.sort(reverse=False)


print(run[K-1])

from collections import deque
K = int(input())
que = deque(list(range(1, 10)))
for i in range(K):
    x = que.popleft()
    last = x % 10
    if last != 0:
        que.append(x*10 + last-1)
    que.append(x*10 + last)
    if last != 9:
        que.append(x*10 + last+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):
#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)

import queue

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

Verdicts: Runtime Error

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

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

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

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 - 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 copy
k = int(input())

cnt = 0
for i in range(1, 100000):
  if i < 9:
    cnt += 1
  else:
    num = copy.copy(i)
    nei = []
    while num < 10:
      nei.append(num%10)
      num /= 10
    for j in range(len(nei)):
      if abs(nei[j] - nei[j+1]) > 1:
        break
      elif abs(nei[j] - nei[j+1]) <= 1 and nei[j] == nei[len(nei)-1]:
        cnt += 1
        
  if cnt == k:
    print(i)
    break

from queue import Queue
q = Queue()

k = int(input())

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

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):
from collections import deque
K = int(input())
q = deque(str(i) for i in range(1, 10))
cnt = 9
if K < 10:
    print(K); return
while True:
    tmp = q.popleft()
    las = int(tmp[-1])
    for i in range(las-1, las+2):
        if 0<=i<=9:
            q.append(tmp + str(i))
            cnt += 1
            if cnt==K:
                print(q.pop()); return

from numba import jit

@njit
def resolve():
	from collections import deque
	K = int(input())
	q = deque(str(i) for i in range(1, 10))
	cnt = 9
	if K < 10:
		print(K); return
	while True:
		tmp = q.popleft()
		las = int(tmp[-1])
		for i in range(las-1, las+2):
			if 0<=i<=9:
				q.append(tmp + str(i))
				cnt += 1
				if cnt==K:
					print(q.pop()); return
resolve()

def resolve():
	from collections import deque
	K = int(input())
	q = deque(str(i) for i in range(1, 10))
	cnt = 9
	if K < 10:
		print(K); return
	while True:
		tmp = q.popleft()
		las = int(tmp[-1])
		for i in range(las-1, las+2):
			if 0<=i<=9:
				q.append(tmp + str(i))
				cnt += 1
				if cnt==K:
					print(q.pop()); return
resolve()

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):
from collections import deque

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

K = read_int()[0]

q = deque()
for i in range(1, 10):
    q.append(i)
def solve():
    for _ in range(K - 1):
        x = q.popleft()
        if x % 10 != 0:
            q.append(10 * x + (x % 10 - 1))
        q.append(10 * x + (x % 10))
        if x % 10 != 9:
            q.append(10 * x + + (x % 10 + 1))
    print()
    return q.popleft()

if __name__ == "__main__":
    print(solve())

from collections import deque
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

K = read_int()[0]

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

def solve():
    for _ in range(K - 1):
        x = q.popleft()
        if x % 10 != 0:
            q.append(10 * x + (x % 10 - 1))
        q.append(10 * x + (x % 10))
        if x % 10 != 9:
            q.append(10 * x + + (x % 10 + 1))
    return q.popleft()

if __name__ == "__main__":
    print(solve())

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


def lunlun():
    k = int(input())
    q = deque(list(range(1, 10)))

    while k > 0:
        k -= 1
        n = q.popleft()
        # print('====== popleft:', n)

        if n % 10 != 0:
            n0 = int(str(n) + str(n % 10 - 1))
            q.append(n0)
            # print('=== append:', n0)

        n1 = int(str(n) + str(n % 10))
        q.append(n1)
        # print('=== append:', n1)

        if n % 10 != 9:
            n2 = int(str(n) + str(n % 10 + 1))
            q.append(n2)
            # print('=== append:', n2)

    print('answer:', n)


##########
if __name__ == "__main__":
    lunlun()


from collections import deque


def lunlun():
    k = int(input())
    q = deque(list(range(1, 10)))

    while k > 0:
        k -= 1
        n = q.popleft()
        # print('====== popleft:', n)

        if n % 10 != 0:
            n0 = int(str(n) + str(n % 10 - 1))
            q.append(n0)
            # print('=== append:', n0)

        n1 = int(str(n) + str(n % 10))
        q.append(n1)
        # print('=== append:', n1)

        if n % 10 != 9:
            n2 = int(str(n) + str(n % 10 + 1))
            q.append(n2)
            # print('=== append:', n2)

    print(n)


##########
if __name__ == "__main__":
    lunlun()


Verdicts: Wrong Answer

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
import queue
k=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
c=0
while c<k:
  a=q.get()
  c+=1
  print("{}番目:{}".format(c,a))
  if c==k:
    print(a)
  if (a%10)!=0:
    q.put(10*a+a%10-1)
  q.put(10*a+a%10)
  if (a%10)!=9:
    q.put(10*a+a%10+1)

import queue
k=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
c=0
while c<k:
  a=q.get()
  c+=1
  if c==k:
    print(a)
  if (a%10)!=0:
    q.put(10*a+a%10-1)
  q.put(10*a+a%10)
  if (a%10)!=9:
    q.put(10*a+a%10+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
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(l)

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

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

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

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

def f(x):
    
    min_x = int(list(str(x))[-1])
    x = str(x)
    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.heappush(l, y)
print(ans)

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):
def dp(i, j, memo):
    key = "{}.{}".format(i, j)

    if i == 1:
        memo[key] = 1
        return memo[key]

    if key in memo:
        return memo[key]

    if j == 0:
        memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)
        return memo[key]

    if j == 9:
        memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)
        return memo[key]

    memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)
    return memo[key]


k = int(input())
memo = {"1.0": 0}

num = 0

i = 1
j = 0

while(num < k):
    j += 1
    j %= 10
    if j == 0:
        i += 1
    else:
        num += dp(i, j, memo)

p = k - num + dp(i, j, memo)
ans = [j]
print(i, j)
for l in range(1, i):
    n = 0
    x = max(-1, ans[-1] - 2)
    while n < p and x < 10:
        x += 1
        n += dp(i-l, x, memo)
    ans.append(x)
    p = p - n + dp(i-l, x, memo)

print("".join(map(str, ans)))


def dp(i, j, memo):
    key = "{}.{}".format(i, j)

    if i == 1:
        memo[key] = 1
        return memo[key]

    if key in memo:
        return memo[key]

    if j == 0:
        memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)
        return memo[key]

    if j == 9:
        memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)
        return memo[key]

    memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)
    return memo[key]


k = int(input())
memo = {"1.0": 0}

num = 0

i = 1
j = 0

while(num < k):
    j += 1
    j %= 10
    if j == 0:
        i += 1
    else:
        num += dp(i, j, memo)

p = k - num + dp(i, j, memo)
ans = [j]
for l in range(1, i):
    n = 0
    x = max(-1, ans[-1] - 2)
    while n < p and x < 10:
        x += 1
        n += dp(i-l, x, memo)
    ans.append(x)
    p = p - n + dp(i-l, x, memo)

print("".join(map(str, ans)))


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):
#!/usr/bin/env python3
ans = [0] * 10
ans[1] = '1'
for i in range(2, 10):
    ans[i] = str(i)
alpha = "0123456789"
def dfs(s):
    if len(s) == N:
        ans.append(s)
        if len(ans) >= 100001:
            return
    else:
        for c in range(int(s[-1])-1,int(s[-1])+2):
            if c >= 0:
                dfs(s+str(c))
            if c == '9':
                break
K = int(input())
N = 2
while len(ans) < 100001:
    for i in range(1, 10):
        dfs(str(i))
        if len(ans) >= 100001:
            break
    N+=1

print(ans[K])

#!/usr/bin/env python3
ans = [0] * 10
ans[1] = '1'
for i in range(2, 10):
    ans[i] = str(i)
alpha = "0123456789"
def dfs(s):
    if len(s) == N:
        ans.append(s)
        if len(ans) >= 100001:
            return
    else:
        for c in (int(s[-1])-1,int(s[-1])+2):
            if c >= 0:
                dfs(s+str(c))
            if c == '9':
                break
K = int(input())
N = 2
while len(ans) < 100001:
    for i in range(1, 10):
        dfs(str(i))
        if len(ans) >= 100001:
            break
    N+=1

print(ans[K])

#!/usr/bin/env python3
ans = [0] * 10
ans[1] = '1'
for i in range(2, 10):
    ans[i] = str(i)
alpha = "0123456789"
def dfs(s):
    if len(s) == N:
        ans.append(s)
        if len(ans) >= 100001:
            return
    else:
        for c in range(int(s[-1])-1,int(s[-1])+2):
            if c >= 0:
                dfs(s+str(c))
            if c == 9:
                break
K = int(input())
N = 2
while len(ans) < 100001:
    for i in range(1, 10):
        dfs(str(i))
        if len(ans) >= 100001:
            break
    N+=1

print(ans[K])

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):
from collections import deque
K = int(input())
d = deque(range(1, 10))
for i in range(K):
    x = d.popleft()
    if x % 10 != 0:
        d.append(10*x-1)
    d.append(10*x)
    if x % 10 != 9:
        d.append(10*x+1)
print(x)

from collections import deque
K = int(input())
d = deque(range(1, 10))
for i in range(K):
    x = d.popleft()
    if x % 10 != 0:
        d.append(10*x+(x % 10)-1)
    d.append(10*x+(x % 10))
    if x % 10 != 9:
        d.append(10*x+(x % 10)+1)
print(x)

Verdicts: Wrong Answer

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
cur = []

def recur(n):
    if n > 10 ** 18:
        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]))

cur = []

def recur(n):
    if n > 10 ** 10:
        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]))

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):
# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]

queue = deque(queue)
L = []
cnt = 0
while cnt <= K:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v + v[-1])
        queue.append(v+str(t+1))
    cnt += 1
print(v)

# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]

queue = deque(queue)
L = []
cnt = 0
while cnt < K:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v + v[-1])
        queue.append(v+str(t+1))
    cnt += 1
print(v)

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())
 
from collections import deque
q = deque(range(1, 10))

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

k=int(input())

from collections import deque
q = deque(range(1,10))

for i in range(k-1):
    d = q.popleft()
    #10
    if d % 10 != 0:
        q.append(10 * d + d % 10 - 1)
    #11
    q.append(10 * d + d % 10)
    #12
    if d % 10 != 9:
        q.append(10 * d + 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):

import sys

sys.setrecursionlimit(10**9)

def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(input())
t = True
k=1
b = 0
while t:
    a = runrun(k)
    b = 0
    
    for i in range(len(a)):
        b+=(len(a[i]))
        
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0

            for i in range(len(tmp)):
                c += (len(tmp[i]))
            s = a[k-1][x-c-1]
            print(int(s))
    else:
        k += 1
        print(b)


import sys

sys.setrecursionlimit(10**9)

from functools import lru_cache
@lru_cache(maxsize=None)

def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(input())
t = True
k=1
b = 0
while t:
    a = runrun(k)
    b = 0
    
    for i in range(len(a)):
        b+=(len(a[i]))
        
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0

            for i in range(len(tmp)):
                c += (len(tmp[i]))
            s = a[k-1][x-c-1]
            print(int(s))
    else:
        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):
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math


def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []
attack = 100000
while attack > 0:
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a += (ue,ue+1)
    elif shimo == 9:
        a += (ue+shimo-1,ue+shimo)
    else:
        a += (ue+shimo-1,ue+shimo,ue+shimo+1)
    attack -= 1

print(b[K-1])

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math


def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []

for i in range(100000):
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a += (ue,ue+1)
    elif shimo == 9:
        a += (ue+shimo-1,ue+shimo)
    else:
        a += (ue+shimo-1,ue+shimo,ue+shimo+1)

print(b[K-1])

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math


def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []
attack = 100000
while attack > 0:
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a.append(ue)
        a.append(ue+1)
    elif shimo == 9:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
    else:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
        a.append(ue+shimo+1)
    attack -= 1

print(b[K-1])

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
import math


K = int(stdin.readline().rstrip())
a = deque(range(1,10))
ans_list = deque()
attack = 100000
while attack > 0:
    ans = a.popleft()
    ue = ans*10
    shimo = ans%10
    ans_list.append(ans)
    if shimo == 0:
        a.append(ue)
        a.append(ue+1)
    elif shimo == 9:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
    else:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
        a.append(ue+shimo+1)
    attack -= 1

print(ans_list[K-1])

Verdicts: Time Limit Exceeded

Time Limit Exceeded

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())
number=[]
for i in range(3234566668):
    k=str(i)
    if all([abs(int(k[j])-int(k[j-1]))<=1 for j in range(1,len(k))]):
        number.append(k)
print(number[K])

from collections import deque
K=int(input())
queue=deque(list(range(1,10)))
for i in range(K):
    k=queue.popleft()
    mod=k%10
    for diff in range(mod-1,mod+2):
        if diff<0 or 9<diff:
            continue
        queue.append(10*k+diff)
print(k)

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 collections

def main():
    k = int(input())
    Q = collections.deque([int(i) for i in range(1, 10)])
    for i in range(k):
        x = Q.popleft()
        if i + len(Q) < k:
            if x%10:
                Q.append(10*x + x%10 - 1)
            Q.append(10*x + x%10)
            if x%10 != 9:
                Q.append(10*x + x%10 + 1)
        print(Q)
    print(x)

if __name__ == "__main__":
    main()

import collections

def main():
    k = int(input())
    Q = collections.deque([int(i) for i in range(1, 10)])
    chk = False
    for i in range(k):
        x = Q.popleft()
        if i + len(Q) > k:
            chk = True
        if chk:
            continue
        else:
            if x%10:
                Q.append(10*x + x%10 - 1)
            Q.append(10*x + x%10)
            if x%10 != 9:
                Q.append(10*x + x%10 + 1)
    print(x)

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):
for i in range(N):
	if (A[i]*4*M) >= vote_sum:
		cnt += 1
	if cnt == M:
		print(y)
		break
		
if C < M:
	print(n)

N, M = map(int, input().split())
A = list(map(int, input().split()))
vote_sum = sum(A)
cnt = 0
y = "Yes"
n = "No"

for i in range(N):
	if (A[i]*4*M) >= vote_sum:
		cnt += 1
	if cnt == M:
		print(y)
		break
		
if C < M:
	print(n)

N, M = map(int, input().split())
A = list(map(int, input().split()))
vote_sum = sum(A)
cnt = 0
y = "Yes"
n = "No"

for i in range(N):
	if (A[i]*4*M) >= vote_sum:
		cnt += 1
	if cnt == M:
		print(y)
		
if C < M:
	print(n)

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

q = deque([i for i in range(1, 10)])

for i in range(K):
    x = q.popleft()
    amari = x%10
    if amari == 0:
        l, m = 10*x, 10*x+1
        q.append(l)
        q.append(m)
    elif amari == 1:
        l, m, r = x*10, x*10+1, x*10+2
        q.append(l)
        q.append(m)
        q.append(r)
    elif amari == 9:
        l, m = 10*x+8, 10*x+9
        q.append(l)
        q.append(m)
    else:
        l, m, r = 10*x+(amari-1), 10*x+(amari), 10*x+(amari+1)
        q.append(l)
        q.append(m)
        q.append(r)

print(x)


Verdicts: Runtime Error

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())
count =0 
j =0 
while True:
    j+=1
    t = [int(i) for i in list(str(j))]
    a = len(t)
    for i,v in enumerate(t):
        if i < a-1:
            if abs(t[i] - t[i+1]) > 1:
                break
    count += 1
    if count ==K:
        print(j)
        exit()

import queue

K = int(input())

q = queue.Queue()
ans = []
cnt = 0
for i in range(1,10):
    q.put(i)
    ans.append(i)
    cnt += 1

while cnt <= 10**5:
    n = q.get()
    m = n %10
    if m == 0:
        q.put(n*10+0)
        q.put(n*10+1)
        ans.append(n*10)
        ans.append(n*10+1)
        cnt += 1
    elif m == 9:
        q.put(n*10+8)
        q.put(n*10+9)
        ans.append(n*10+8)
        ans.append(n*10+9)
        cnt += 2
    else:
        q.put(n*10+m-1)
        q.put(n*10+m)
        q.put(n*10+m+1)
        ans.append(n*10+m-1)
        ans.append(n*10+m)
        ans.append(n*10+m+1)
        cnt += 3

print(ans[K-1])

Verdicts: Wrong Answer

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
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)


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)


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 + a%10 - 1)
    
    nums.append(a*10 + a%10)
    
    if a%10!=9:
        nums.append(a*10 + a%10 + 1)

print(a)

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

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)
  
  

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 l%10 !=0:
    num.append(l*10+(l%10-1))
  num.append(l*10+(l %10))
  if l%10 != 9:
    num.append(l*10+(l%10+1))

print(l)

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
from functools import lru_cache
sys.setrecursionlimit(10**9)
k = int(input())
lunlun = []


@lru_cache(maxsize=100000000)
def func(i):
    if int(i) > 3234566667 + 10 or len(i) > 6:
        return
    lunlun.append(int(i))
    f = int(i[0])
    b = int(i[-1])
    if f != 0:
        func(f'{f-1}{i}')
    if f != 9:
        func(f'{f+1}{i}')
    func(f'{f}{i}')
    if b != 0:
        func(f'{i}{b-1}')
    if b != 9:
        func(f'{i}{b+1}')
    func(f'i}{b}')


for i in range(10):
    func(str(i))
lunlun = sorted(set(lunlun))
print(len(lunlun))
print(lunlun[k])


from collections import deque

k = int(input())
q = deque(range(1, 10))
for _ in range(k):
    x = q.popleft()
    r = x % 10
    if r != 0:
        q.append(10*x + (r - 1))
    q.append(10*x+r)
    if r != 9:
        q.append(10*x + (r + 1))
print(x)


Verdicts: Runtime Error

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
import 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:  
            tmp.append(n * 10 + (n % 10 - 1))
        tmp.append(n * 10 + (n % 10))
        if n % 10 != 9:  
            tmp.append(n * 10 + (n % 10 + 1))
    lunlun_number.append(tmp)
lunlun_number = np.array(lunlun_number).flatten()
print(lunlun_number[K - 1])


import numpy as np
K = int(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:  
            tmp.append(n * 10 + (n % 10 - 1))
        tmp.append(n * 10 + (n % 10))
        if n % 10 != 9:  
            tmp.append(n * 10 + (n % 10 + 1))
    lunlun_number.append(tmp)
lunlun_number = [flatten for inner in lunlun_number for flatten in inner]
print(lunlun_number[K - 1])


Verdicts: Runtime Error

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
k = int(input())
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)


k = int(input())
a = [i for i in range(1, 10)]
while True:
    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)


Verdicts: Runtime Error

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
n=int(input())
now=[1,2,3,4,5,6,7,8,9]
if n<10:
  print(now[n-1])
  exit()
cnt=9
while True:
  next=[]
  for s in now:
    s=str(s)
    if s[-1]!=0:
      cnt+=1
      if cnt<n:
        next.append(s+"0")
      else:
        print(s+"0")
        exit()
    cnt+=1
    if cnt<n:
      next.append(s+s[-1])
    else:
      print(s+s[-1])
      exit()
    if s[-1]!=9:
      cnt+=1
      if cnt<n:
        next.append(s+"9")
      else:
        print(s+"9")
        exit()
  now=next

n=int(input())
now=[1,2,3,4,5,6,7,8,9]
if n<10:
  print(now[n-1])
  exit()
cnt=9
while True:
  next=[]
  for s in now:
    s=str(s)
    if s[-1]!="0":
      cnt+=1
      if cnt<n:
        next.append(s+str(int(s[-1]-1)))
      else:
        print(s+str(int(s[-1]-1)))
        exit()
    cnt+=1
    if cnt<n:
      next.append(s+s[-1])
    else:
      print(s+s[-1])
      exit()
    if s[-1]!="9":
      cnt+=1
      if cnt<n:
        next.append(s+str(int(s[-1]+1)))
      else:
        print(s+str(int(s[-1]+1)))
        exit()
  now=next


n=int(input())
now=[1,2,3,4,5,6,7,8,9]
if n<10:
  print(now[n-1])
  exit()
cnt=9
while True:
  next=[]
  for s in now:
    s=str(s)
    if s[-1]!="0":
      cnt+=1
      if cnt<n:
        next.append(s+str(int(s[-1])-1))
      else:
        print(s+str(int(s[-1])-1))
        exit()
    cnt+=1
    if cnt<n:
      next.append(s+s[-1])
    else:
      print(s+s[-1])
      exit()
    if s[-1]!="9":
      cnt+=1
      if cnt<n:
        next.append(s+str(int(s[-1])+1))
      else:
        print(s+str(int(s[-1])+1))
        exit()
  now=next


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
import queue
k = int(input())
q = queue.Queue([1,2,3,4,5,6,7,8,9])
c = 1
while True:
  x = q.get()
  if c == k:
    print(x)
    exit()
  if x%10 == 0:
    q.put(10*x)
    q.put(10*x+1)
  elif x%10 == 0:
    q.put(10*x+8)
    q.put(10*x+9)
  else:
    i = x%10
    q.put(10*x+i-1)
    q.put(10*x+i)
    q.put(10*x+i+1)
  c += 1
    
    
    


k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])  
  
  
  

Verdicts: Time Limit Exceeded

Accepted