qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
from _collections import deque

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

if K <= 9:
    print(K)
else:
    while(True):
        a = q.popleft()
        if a % 10 == 0:
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print(a*10+1)
                sys.exit()
            q.append(a*10+1)
        elif a % 10 == 9:
            c += 1
            if c == K:
                print(a*10-1)
                sys.exit()
            q.append(a*10-1)
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
        else:
            c += 1
            if c == K:
                print(a*10-1)
                sys.exit()
            q.append(a*10-1)
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print(a*10+1)
                sys.exit()
            q.append(a*10+1)

Fixed code:
import sys
from _collections import deque

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

if K <= 9:
    print(K)
else:
    while(True):
        a = q.popleft()
        if a % 10 == 0:
            c += 1
            if c == K:
                print(a*10)
                sys.exit()
            q.append(a*10)
            c += 1
            if c == K:
                print(a*10+1)
                sys.exit()
            q.append(a*10+1)
        elif a % 10 == 9:
            c += 1
            if c == K:
                print(a*10+9-1)
                sys.exit()
            q.append(a*10+9-1)
            c += 1
            if c == K:
                print(a*10+9)
                sys.exit()
            q.append(a*10+9)
        else:
            c += 1
            if c == K:
                print(a*10+a%10-1)
                sys.exit()
            q.append(a*10+a%10-1)
            c += 1
            if c == K:
                print(a*10+a%10)
                sys.exit()
            q.append(a*10+a%10)
            c += 1
            if c == K:
                print(a*10+a%10+1)
                sys.exit()
            q.append(a*10+a%10+1)
Buggy 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])

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

k = int(input())
l = 10
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])
Buggy code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print(10 * x + y - 1)
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print(10 * x + y)
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print(10 * x + y + 1)
            exit()
        q.append(10 * x + y + 1)


Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
    exit()
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print(10 * x + y - 1)
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print(10 * x + y)
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print(10 * x + y + 1)
            exit()
        q.append(10 * x + y + 1)
Buggy code:
from collections import deque
def main(k):
    q = deque([])
    for i in range(10):
        q.append(i)
    
    count = 0
    top = -1
    while True:
        top = q.popleft()

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

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

    return top

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

Fixed 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
k = int(input())
print(main(k))
Buggy code:
k=int(input())
list=[1,2,3,4,5,6,7,8,9]
for i in range(k-1):
  m=list[i]
  n=m*10+m%10
  if m%10!=0:
    list.append(m-1)
  list.append(m)
  if m%10!=9:
    list.append(m+1)
print(list[k-1])

Fixed code:
k=int(input())
list=[1,2,3,4,5,6,7,8,9]
for i in range(k-1):
  m=list[i]
  n=m*10+m%10
  if m%10!=0:
    list.append(n-1)
  list.append(n)
  if m%10!=9:
    list.append(n+1)
print(list[k-1])
Buggy 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])

Fixed 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
        n = 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+mod, n+mod+1])
        index += 1
    
    return lun_luns[k-1]

print(fun(k))
Buggy 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)
    

Fixed code:
from collections import deque

k = int(input())

q = deque()

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)
Buggy code:
que = queue.Queue()

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

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

Fixed code:
k = int(input())

import queue

que = queue.Queue()

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

for i in range(1, k + 1):
    ans = que.get()
    keta1 = ans % 10
    if keta1 == 0:
        append_list = [ans * 10, ans * 10 + 1]
    elif keta1 == 9:
        append_list = [ans * 10 + 8, ans * 10 + 9]
    else:
        append_list = [ans * 10 + keta1 - 1, ans * 10 + keta1, ans * 10 + keta1 + 1]
    for item in append_list:
        que.put(item)
print(ans)
Buggy code:
import queue
K=int(input())
x=queue.Queue()
for j in range(0,9):
    x.put(j)
for i in range(K+1):
    y=x.get()
    if y%10!=0:
        x.put(10*y+y%10-1)
    x.put(10*y+y%10)
    if y%10!=9:
        x.put(10*y+y%10+1)
print(x.get())

Fixed code:
import queue
K=int(input())
x=queue.Queue()
for j in range(1,10):
    x.put(j)
for i in range(K):
    y=x.get()
    if y%10!=0:
        x.put(10*y+y%10-1)
    x.put(10*y+y%10)
    if y%10!=9:
        x.put(10*y+y%10+1)
print(y)
Buggy 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()
    

Fixed code:
from collections import deque

def make_lunlun():
    lst = []
    que = deque([1,2,3,4,5,6,7,8,9])
    for i in range(100000):
        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()
Buggy 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()

    p = 10 * x  
    m = x % 10
    if not p == 0:
        q.put(p + m - 1)

    q.put(p + m)

    if not p == 9:
        q.put(p + m + 1)
    
print(x)


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

    p = 10 * x  
    m = x % 10
    if not m == 0:
        q.put(p + m - 1)

    q.put(p + m)

    if not m == 9:
        q.put(p + m + 1)
    
print(x)
Buggy code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    for k in range(K - 1):
        x = q.pop(0)
        mod = x % 10
        if mod == 0:
            q.append(10 * x)
            q.append(10 * x + 1)
        elif mod == 9:
            q.append(10 * x - 1)
            q.append(10 * x)
        else:
            q.append(10 * x + mod - 1)
            q.append(10 * x + mod)
            q.append(10 * x + mod + 1)

    print(q[0])


if __name__ == '__main__':
    main()


Fixed code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    for k in range(0, K):
        x = q[k]
        mod = x % 10
        if mod != 0:
            q.append(10 * x + mod - 1)
        q.append(10 * x + mod)
        if mod != 9:
            q.append(10 * x + mod + 1)

    print(q[K-1])


if __name__ == '__main__':
    main()
Buggy code:
def lun(s):
    ch = 1
    temp = int(s[0])
    for i in s[1: ]:
        i = int(i)
        if abs(i - temp) > 1:
            ch = 0
            break
        temp = i
    return ch
k = int(input())
d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
while 1:
    for i in l:
        for j in d:
            # print(i, j)
            s = i + str(j)
            if lun(s): l.append(s)
        if len(l) >= 10000: break
    if len(l) >= 10000: break
k = input()
print(l[k])

Fixed code:
def lun(s):
    ch = 1
    temp = int(s[0])
    for i in s[1: ]:
        i = int(i)
        if abs(i - temp) > 1:
            ch = 0
            break
        temp = i
    return ch
k = int(input())
d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
while 1:
    for i in l:
        for j in d:
            # print(i, j)
            s = i + str(j)
            if lun(s): l.append(s)
        if len(l) >= 100002: break
    if len(l) >= 100002: break
print(l[k - 1])
Buggy code:
k=int(input())

que=list(range(1,9+1))

while True:
 k-=len(que)
 for q in que[:]:
    que.remove(q)
    lq=int(str(q)[-1])
    for r in (lq-1,lq,lq+1):
        if 0<=r<=9:
            que.append(int(str(q)+str(r)))
 # print(que)
 
 if len(que)>=k:
    break
 
que.sort()
print(que[k-1])

Fixed code:
k=int(input())

que=list(range(1,9+1))

while True:
  if len(que)>=k:
    break
  k-=len(que)
  for q in que[:]:
    que.remove(q)
    lq=int(str(q)[-1])
    for r in (lq-1,lq,lq+1):
        if 0<=r<=9:
            que.append(int(str(q)+str(r)))
 
  if len(que)>=k:
    break
 
que.sort()
print(que[k-1])
Buggy code:
# https://atcoder.jp/contests/abc161/tasks/abc161_d

import sys
# sys.setrecursionlimit(100000)
import heapq


def input():
    return sys.stdin.readline().strip()


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


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = int(input())
    if n < 10:
        print(n)
    cnt = 0
    hq = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    while cnt < n:
        i = heapq.heappop(hq)
        cnt += 1
        if cnt == n:
            print(i)
            return
        r = int(str(i)[::-1][0])
        heapq.heappush(hq, int(str(i) + str(r)))
        if r != 9:
            heapq.heappush(hq, int(str(i) + str(r + 1)))
        if r != 0:
            heapq.heappush(hq, int(str(i) + str(r - 1)))
    return


if __name__ == "__main__":
    main()


Fixed code:
# https://atcoder.jp/contests/abc161/tasks/abc161_d

import sys
# sys.setrecursionlimit(100000)
import heapq


def input():
    return sys.stdin.readline().strip()


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


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = int(input())
    if n < 10:
        print(n)
        return
    cnt = 0
    hq = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    while cnt < n:
        i = heapq.heappop(hq)
        cnt += 1
        if cnt == n:
            print(i)
            return
        r = int(str(i)[::-1][0])
        heapq.heappush(hq, int(str(i) + str(r)))
        if r != 9:
            heapq.heappush(hq, int(str(i) + str(r + 1)))
        if r != 0:
            heapq.heappush(hq, int(str(i) + str(r - 1)))
    return


if __name__ == "__main__":
    main()
Buggy 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])

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

ans_list = []
def dfs(A):
    if len(A)!=0 and int("".join(A))<=10**10:
        ans_list.append(int("".join(A)))
    elif len(A)!=0 and int("".join(A))>10**10:
        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])
Buggy code:
k = int(input())
l = ['1','2','3','4','5','6','7','8','9']
lf = ['1','2','3','4','5','6','7','8','9']
sum = 9
while sum < k:
    lff = []
    for i in lf:
        if i[-1] == [0]:
            lff.append(i+'0')
            lff.append(i+'1')
        elif i[-1] == [9]:
            lff.append(i+'8')
            lff.append(i+'9')
        else:
            lff.append(i+str(int(i[-1]-1)))
            lff.append(i+str(int(i[-1])))
            lff.append(i+str(int(i[-1]+1)))
    lf = lff
    l += lff
print(l[k-1])

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

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

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()


Fixed code:
from collections import deque

def main():
    K = int(input())
    if K <= 9:
        print(K)
        return

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()
Buggy code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(read())

pre_lis = []
for i in range(1,10):
    pre_lis.append(str(i))
print(pre_lis)
ct = 9
if K <= 9:
    print(pre_lis[K-1])
else:
    new_lis = []
    flag = False
    while ct < K:
        for num in pre_lis:
            pre_num = int(num[-1])
            for i in range(10):
                if abs(pre_num-i) <= 1:
                    new_lis.append(num + str(i))
                    ct+=1
                    #print((new_lis[-1]))
                    if ct == K:
                        print(new_lis[-1])
                        flag = True
                        break
            pre_lis = new_lis
            if flag:
                break
        if flag:
            break

Fixed code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(read())

pre_lis = []
for i in range(1,10):
    pre_lis.append(str(i))
    
ct = 9
if K <= 9:
    print(pre_lis[K-1])
else:
    new_lis = []
    flag = False
    while ct < K:
        for num in pre_lis:
            pre_num = int(num[-1])
            for i in range(10):
                if abs(pre_num-i) <= 1:
                    new_lis.append(num + str(i))
                    ct+=1
                    if ct == K:
                        print(new_lis[-1])
                        flag = True
                        break
            pre_lis = new_lis
            if flag:
                break
        if flag:
            break
Buggy code:
k = int(input())
n = 1
cnt = 0
flg = 0
while True:
  if flg == 1:
    n += 1
  flg = 0
  strn = str(n)
  if len(strn) == 1:
    cnt += 1
    n += 1
  else:
    for s in range(len(strn)):
      if s == len(strn) - 1:
        cnt += 1
        flg = 1
      else:
        if abs(int(strn[s]) - int(strn[s+1])) > 1:
          if int(strn[s]) - int(strn[s+1]) > 1:
            new = ''
            for ss in range(len(strn)):
              if s+1 == ss:
                new += str(int(strn[s]) - 1)
              else:
                new += strn[ss]
            n = int(new)
          else:
            new = ''
            for ss in range(len(strn)):
              if s == ss:
                new += str(int(strn[s]) + 1)
              elif s+1 == ss:
                new += '0'
              else:
                new += strn[ss]
            n = int(new)
          break
          
    
  if cnt == k:
    print(n)
    break


Fixed code:
k = int(input())
n = 1
cnt = 0
flg = 0
while True:
  if flg == 1:
    n += 1
  flg = 0
  strn = str(n)
  if len(strn) == 1:
    cnt += 1
    flg = 1
  else:
    for s in range(len(strn)):
      if s == len(strn) - 1:
        cnt += 1
        flg = 1
      else:
        if abs(int(strn[s]) - int(strn[s+1])) > 1:
          if int(strn[s]) - int(strn[s+1]) > 1:
            new = ''
            for ss in range(len(strn)):
              if s+1 == ss:
                new += str(int(strn[s]) - 1)
              else:
                new += strn[ss]
            n = int(new)
          else:
            new = ''
            for ss in range(len(strn)):
              if s == ss:
                new += str(int(strn[s]) + 1)
              elif s+1 == ss:
                new += '0'
              else:
                new += strn[ss]
            n = int(new)
          break
          
    
  if cnt == k:
    print(n)
    break
Buggy code:
from queue import Queue

K = int(input())

# 1 2 3 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34 ... 98 99 100

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

# print(q.queue)

for i in range(K):
    r = q.get()
    
    if r % 10 != 0:
        q.put(r * 10 + r % 10 - 1)

    q.put(r * 10)

    if r % 10 != 9:
        q.put(r * 10 + r % 10 + 1)
        
print(r)


Fixed code:
from queue import Queue

K = int(input())

# 1 2 3 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34 ... 98 99 100

q = Queue()

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

for _ in range(K):
    x = q.get()
    
    if x % 10 != 0:
        q.put(x * 10 + x % 10 - 1)

    q.put(x * 10 + x % 10)

    if x % 10 != 9:
        q.put(x * 10 + x % 10 + 1)

        
print(x)