qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main():
    k=int(input())
    l=[[] for _ in range(20)]
    l[1]=[0,1,2,3,4,5,6,7,8,9]
    cnt=9
    if cnt>=k:
        print(l[k])
        exit()
    for i in range(2,20):
        for keta in range(1,i):
            for j in l[keta]:
                f=j//10**(i-2)
                if j==0:
                    l[i].append(10**(i-1)+j)
                if f==0:
                    if j//10**(len(str(j))-1)==1:
                        l[i].append(10**(i-1)+j)
                elif f==1:
                    l[i].append(10**(i-1)+j)
                    l[i].append(2*10**(i-1)+j)
                elif f==9:
                    l[i].append(8*10**(i-1)+j)
                    l[i].append(9*10**(i-1)+j)
                elif f>0:
                    l[i].append((f-1)*10**(i-1)+j)
                    l[i].append(f*10**(i-1)+j)
                    l[i].append((f+1)*10**(i-1)+j)
            if cnt+len(l[i])>=k:
                l[i].sort()
                ans=l[i][k-cnt-1]
                if ans==0:
                    print(10**(i-1))
                else:
                    l[4].sort()
                    print(l[4])
                    print(ans)
                exit()
            else:
                cnt+=len(l[i])

if __name__ == '__main__':
    main()

Fixed code:
def main():
    k=int(input())
    l=[[] for _ in range(20)]
    l[1]=[0,1,2,3,4,5,6,7,8,9]
    cnt=9
    if cnt>=k:
        print(l[1][k])
        exit()
    for i in range(2,20):
        for keta in range(1,i):
            for j in l[keta]:
                f=j//10**(i-2)
                if j==0:
                    l[i].append(10**(i-1)+j)
                if f==0:
                    if j//10**(len(str(j))-1)==1:
                        l[i].append(10**(i-1)+j)
                elif f==1:
                    l[i].append(10**(i-1)+j)
                    l[i].append(2*10**(i-1)+j)
                elif f==9:
                    l[i].append(8*10**(i-1)+j)
                    l[i].append(9*10**(i-1)+j)
                elif f>0:
                    l[i].append((f-1)*10**(i-1)+j)
                    l[i].append(f*10**(i-1)+j)
                    l[i].append((f+1)*10**(i-1)+j)
        if cnt+len(l[i])>=k:
            l[i].sort()
            ans=l[i][k-cnt-1]
            if ans==0:
                print(10**(i-1))
            else:
                print(ans)
            exit()
        else:
            cnt+=len(l[i])

if __name__ == '__main__':
    main()
Buggy code:
k=int(input())
a=[i+1 for i in range(9)]
while (1):
  if k<=len(a):
    print(a[k-1])
    f=1
    break
  
  k=k-len(a)
  #print(k)
  b=[]
  for x in a:
    for i in [-1,0,1]:
      d=x%10+i
      #print(d)
      if d<0 or d>10: continue
      b.append(x*10+d)
  a=b.copy()




Fixed code:
k=int(input())
a=[i+1 for i in range(9)]
while (1):
  if k<=len(a):
    print(a[k-1])
    f=1
    break
  
  k=k-len(a)
  #print(k)
  b=[]
  for x in a:
    for i in [-1,0,1]:
      d=x%10+i
      #print(d)
      if d<0 or d>=10: continue
      b.append(x*10+d)
  a=b.copy()
  #print(a)
Buggy code:
k = int(input())

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



Fixed code:
from collections import deque

k = int(input())

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

q = [1,2,3,4,5,6,7,8,9]
i = 0
n = 0
while n < K:
    x = q[i]
    if x % 10 > 0:
        q.append(x * 10 + x - 1)
        n += 1
    q.append(x * 10 + x)
    n += 1
    if x % 10 < 9:
        q.append(x * 10 + x + 1)
        n += 1
    i += 1
print(q[K])

Fixed code:
K = int(input())

q = [1,2,3,4,5,6,7,8,9]
i = 0
n = 9
while n < K:
    x = q[i]
    m = x % 10
    if m > 0:
        q.append(x * 10 + m - 1)
        n += 1
    q.append(x * 10 + m)
    n += 1
    if m < 9:
        q.append(x * 10 + m + 1)
        n += 1
    i += 1
print(q[K-1])
Buggy code:
import heapq
k = int(input())
run_list = [i for i in range(1,10)]
heapq.heapify(run_list)
result = 0
for i in range(k):
  result = heapq.pop(run_list)
  if result % 10 ==0:
    new_1 = result * 10
    new_2 = result * 10 + 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  elif result % 10 ==9:
    new_1 = result * 10 + 8
    new_2 = result * 10 + 9
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  else:
    new_1 = result * 10 + (resut % 10)
    new_2 = result * 10 + (resut % 10) + 1
    new_3 = result * 10 + (resut % 10) - 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
print(result)
    heapq.heappush(run_list, new_3)

Fixed code:
import heapq
k = int(input())
run_list = [i for i in range(1,10)]
heapq.heapify(run_list)
result = 0
for i in range(k):
  result = heapq.heappop(run_list)
  if result % 10 ==0:
    new_1 = result * 10
    new_2 = result * 10 + 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  elif result % 10 ==9:
    new_1 = result * 10 + 8
    new_2 = result * 10 + 9
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
  else:
    new_1 = result * 10 + (result % 10)
    new_2 = result * 10 + (result % 10) + 1
    new_3 = result * 10 + (result % 10) - 1
    heapq.heappush(run_list, new_1)
    heapq.heappush(run_list, new_2)
    heapq.heappush(run_list, new_3)
print(result)
Buggy code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = 0

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

dfs(10, 0, 0)

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

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

    return cnt

dfs(10, 0, 0, cnt)
Buggy code:
k=int(input());l=list(range(1,10))
for i in l:
  if len(l)==k: print(i); break
  for j in range(max(i%10-1,0),min(i%10+2,10)): l+=[i*10+j]

Fixed code:
k=int(input());l=list(range(1,10))
for i in l:
  if len(l)>k: break
  for j in range(max(i%10-1,0),min(i%10+2,10)): l.append(i*10+j)
print(l[k-1])
Buggy code:
from collections import deque

k = int(input())

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

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  que.append(10*x)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)

Fixed code:
from collections import deque

k = int(input())

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

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  que.append(x * 10 + x % 10)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)
Buggy 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])

Fixed 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
      que.append(tmp)  
print(que[k-1-ct])
Buggy code:
K = int(input())
a = ['1','2','3','4','5','6','7','8','9']
if K <= 9:
    print(K)

cnt = 9
while True:
    a_tmp = []
    for s in a:
        for t in range(max(0, int(str(s[-1])) - 1), min(9, int(str(s[-1])) + 1) + 1):
            a_tmp.append(s+str(t))
            cnt += 1
            if cnt == K:
                print(s+str(t))
                exit()
    a = a_tmp




Fixed code:
K = int(input())
a = ['1','2','3','4','5','6','7','8','9']
if K <= 9:
    print(K)
    exit()


cnt = 9
while True:
    a_tmp = []
    for s in a:
        for t in range(max(0, int(str(s[-1])) - 1), min(9, int(str(s[-1])) + 1) + 1):
            a_tmp.append(s+str(t))
            cnt += 1
            if cnt == K:
                print(s+str(t))
                exit()
    a = a_tmp
Buggy code:
def generate(n):
    if n == 1:
        for i in range(1, 10):
            yield [i]
    else:
        for A in generate(n - 1):
            for i in range(10):
                if abs(A[-1] - i) <= 1:
                    yield A + [i]


L = []
for n in range(1, 11):
    for A in generate(n):
        L.append(int(''.join([str(a) for a in A])))
print(len(L))
k = int(input())
print(L[k - 1])


Fixed code:
def generate(n):
    if n == 1:
        for i in range(1, 10):
            yield [i]
    else:
        for A in generate(n - 1):
            for i in range(10):
                if abs(A[-1] - i) <= 1:
                    yield A + [i]


L = []
for n in range(1, 11):
    for A in generate(n):
        L.append(int(''.join([str(a) for a in A])))
k = int(input())
print(L[k - 1])
Buggy code:
import math
import copy
from queue import Queue

n = int(input())
#n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#num = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
#s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

queue = Queue()
temp = 0

if (n < 10):
    print(n)
else:
    for i in range(1,10):
        queue.put(i)
    for i in range(1,n):
        temp = queue.get()
        if (temp % 10 != 0) :
            queue.put(10 * temp + (temp % 10) - 1)
        queue.put(10 * temp + (temp % 10))
        if (temp % 10 != 9) :
            queue.put(10 * temp + (temp % 10) + 1)

print(queue.get())



Fixed code:
import math
import copy
from queue import Queue

n = int(input())
#n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#num = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
#s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

queue = Queue()
temp = 0

if (n < 10):
    print(n)
else:
    for i in range(1,10):
        queue.put(i)
    for i in range(1,n):
        temp = queue.get()
        if (temp % 10 != 0) :
            queue.put(10 * temp + (temp % 10) - 1)
        queue.put(10 * temp + (temp % 10))
        if (temp % 10 != 9) :
            queue.put(10 * temp + (temp % 10) + 1)
    print(queue.get())
Buggy code:
from itertools import product
K = int(input())

ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(''.join(map(str, X)))

ans.sort()
print(ans[K - 1])


Fixed code:
from itertools import product
K = int(input())

ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(int(''.join(map(str, X))))

ans.sort()
print(ans[K - 1])
Buggy code:
def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam)-1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam)-1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam)-1])
            nextNumList = [nextNum-1, nextNum, nextNum+1]
        
        for item in nextNumList:
            print(inParam+str(item))
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            print(myTupp)
            if myTupp[2] == 'e':
                return myTupp
        
        return myTupp
    
    else:
        lunlunCount += 1
        state = 'c'

        if lunlunCount == lunlun:
            state = 'e'
            print(inParam)

        return (lunlunCount, inParam, state)

K = int(input())

mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        if mylunlun == K:
            break
    
    if mylunlun == K:
        break

    mydigits += 1


Fixed code:
def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam)-1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam)-1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam)-1])
            nextNumList = [nextNum-1, nextNum, nextNum+1]
        
        for item in nextNumList:
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            if myTupp[2] == 'e':
                return myTupp
        
        return myTupp
    
    else:
        lunlunCount += 1
        state = 'c'

        if lunlunCount == lunlun:
            state = 'e'
            print(inParam)

        return (lunlunCount, inParam, state)

K = int(input())

mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        if mylunlun == K:
            break
    
    if mylunlun == K:
        break

    mydigits += 1
Buggy code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K=int(input())
c=9
cb=0
r_list=[1,2,3,4,5,6,7,8,9]
while(c<K):
    tmp=[]
    for i in r_list:
        if(i%10==0):
            tmp.append(i*10)
            tmp.append(i*10+1)
        if(i%10==9):
            tmp.append(i*10+8)
            tmp.append(i*10+9)
        else:
            tmp.append(i*10+i%10-1)
            tmp.append(i*10+i%10)
            tmp.append(i*10+i%10+1)
    cb=c
    r_list=tmp
    c+=len(r_list)

    
r_list.sort()
ans=r_list[K-cb-1]
print(ans)


Fixed code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K=int(input())
c=9
cb=0
r_list=[1,2,3,4,5,6,7,8,9]
while(c<K):
    tmp=[]
    for i in r_list:
        if(i%10==0):
            tmp.append(i*10)
            tmp.append(i*10+1)
        elif(i%10==9):
            tmp.append(i*10+8)
            tmp.append(i*10+9)
        else:
            tmp.append(i*10+i%10-1)
            tmp.append(i*10+i%10)
            tmp.append(i*10+i%10+1)
    cb=c
    r_list=tmp
    c+=len(r_list)

    
r_list.sort()
ans=r_list[K-cb-1]
print(ans)
Buggy code:
from collections import deque
num=deque([1,2,3,4,5,6,7,8,9])
cnt=0
K=int(input())
while(True):
    a=num.popleft()
    cnt+=1
    if cnt==K:
        print(a)
        exit()
    if a%10!=0:
        a1=10*a+(a%10)-1
    a2=10*a+a%10
    if a%10!=9:
        a3=10*a+a%10 +1
    num.append(a1)
    num.append(a2)
    num.append(a3)




Fixed code:
from collections import deque
num=deque([1,2,3,4,5,6,7,8,9])
cnt=0
K=int(input())
while(True):
    a=num.popleft()
    cnt+=1
    if cnt==K:
        print(a)
        exit()
    if a%10==0:
        a1=a*10
        a2=a1+1
        num.append(a1)
        num.append(a2)
    elif a%10==9:
        a1=a*10+(a%10)-1
        a2=a*10+(a%10)
        num.append(a1)
        num.append(a2)
    else:
        a1 = a * 10 + (a % 10) - 1
        a2 = a * 10 + (a % 10)
        a3 = a * 10 + (a % 10) + 1
        num.append(a1)
        num.append(a2)
        num.append(a3)
Buggy code:
K=int(input())
import queue
a=queue.Queue()
if K<=9:
  print(K)
else:
  for i in range(1,10):
    a.put(i)
  n=K
  while n>1:
    x=a.get()
    if x%10!=0:
      a.put(10*x-1)
    a.put(10*x)
    if x%10!=9:
      a.put(10*x+1)
    n-=1
  ans=a.get()
  print(ans)

Fixed code:
K=int(input())
import queue
a=queue.Queue()
if K<=9:
  print(K)
else:
  for i in range(1,10):
    a.put(i)
  n=K
  while n>1:
    p=a.get()
    x=p%10
    if x%10!=0:
      a.put(10*p+x-1)
    a.put(10*p+x)
    if x%10!=9:
      a.put(10*p+x+1)
    n-=1
  ans=a.get()
  print(ans)
Buggy code:
k = int(input())
lunlun = [1,2,3,4,5,6,7,8,9]
i = 0
while len(lunlun) < k:
  p = lunlun[i]
  if str(p)[-1] == 0:
    lunlun.append(int(str(p)+'0'))
    lunlun.append(int(str(p)+'1'))
  elif str(p)[-1] == 9:
    lunlun.append(int(str(p)+'8'))
    lunlun.append(int(str(p)+'9'))
  else:
    lunlun.append(int(str(p)+str(int(str(p)[-1])-1)))
    lunlun.append(int(str(p)+str(int(str(p)[-1]))))
    lunlun.append(int(str(p)+str(int(str(p)[-1])+1)))
  i += 1

print(lunlun[k-1])

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

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


Fixed code:
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)
Buggy code:
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 + 10%10)
    if x%10 != 9:
        d.append(10*x + x%10 +1)

print(x)

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

n = int(input())


q = queue.Queue()

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

x = 0
for i in range(n):
    x = q.get()
    l = x % 10
    print(x,l)
    if l != 0:
        q.put(x*10 + l - 1)
    q.put(x*10 + l)
    if l != 9:
        q.put(x*10 + l + 1)
        
#while not q.empty():
#    print (q.get())
    
print(x)


Fixed code:
import queue

n = int(input())


q = queue.Queue()

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

x = 0
for i in range(n):
    x = q.get()
    l = x % 10
#    print(x,l)
    if l != 0:
        q.put(x*10 + l - 1)
    q.put(x*10 + l)
    if l != 9:
        q.put(x*10 + l + 1)
        
#while not q.empty():
#    print (q.get())
    
print(x)
Buggy code:
K = int(input())
s = '0'
cnt = 0
while cnt<K:
  cnt += 1
  ns = ''
  j = -1
  for i in range(len(s)-1,0,-1):
    if int(s[i])+1<=int(s[i-1])+1 and int(s[i])+1<10:
      j = i
      break
  else:
    if s[0]<'9':
      j = 0
  if j!=-1:
    for i in range(len(s)):
      if i==j:
        x = str(int(s[i])+1)
      elif i<j:
        x = s[i]
      elif i==j+1:
        x = str(int(s[j]))
      else:
        x = str(max(int(s[j])-1,0))
      ns += x
  else:
    ns = '1'+'0'*len(s)
  s = ns
#  print(s,)
print(s)

Fixed code:
K = int(input())
s = '0'
cnt = 0
while cnt<K:
  cnt += 1
  ns = ''
  j = -1
  for i in range(len(s)-1,0,-1):
    if int(s[i])+1<=int(s[i-1])+1 and int(s[i])+1<10:
      j = i
      break
  else:
    if s[0]<'9':
      j = 0
  if j!=-1:
    m = int(s[j])
    for i in range(len(s)):
      if i==j:
        x = str(int(s[i])+1)
      elif i<j:
        x = s[i]
      elif i==j+1:
        x = str(m)
      else:
        x = str(max(m-1,0))
        m = max(m-1,0)
      ns += x
  else:
    ns = '1'+'0'*len(s)
  s = ns
#  print(s,)
print(s)
Buggy code:
import queue
target = int(input())

q = queue.Queue()

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


for cnt in range(1, target - 1):
  num = q.get()
  mod = num % 10
  
  if mod == 0:
    q.put(num * 10)
    q.put(num * 10 + 1)
  elif mod == 9:
    q.put(num * 10 + 8)
    q.put(num * 10 + 9)
  else:
    q.put(num * 10 + mod - 1)
    q.put(num * 10 + mod)
    q.put(num * 10 + mod + 1)

print(q.get())

Fixed code:
import queue
target = int(input())

q = queue.Queue()

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


for cnt in range(1, target):
  num = q.get()
  mod = int(num) % 10
  
  if mod == 0:
    q.put(num + "0")
    q.put(num + "1")
  elif mod == 9:
    q.put(num + "8")
    q.put(num + "9")
  else:
    q.put(num + str(mod - 1))
    q.put(num + str(mod))
    q.put(num + str(mod + 1))

print(q.get())
Buggy code:
def is_lunlun(n):
    m = str(n)
    for i in range(1,len(m)):
        if abs(int(m[i]) - int(m[i-1])) > 1:
            return False
    return True

def main():
    K = int(input())
    A = [i for i in range(100000) if is_lunlun(i)]
    B = [int(str(a1)+str(a2)) for a1 in A for a2 in A if is_lunlun(int(str(a1)+str(a2))) and int(str(a1)+str(a2)) < 3234566668]
    B2 = sorted(set(B))
    print(B2[K])

if __name__ == "__main__":
    main()

Fixed code:
def is_lunlun(n):
    m = str(n)
    for i in range(1,len(m)):
        if abs(int(m[i]) - int(m[i-1])) > 1:
            return False
    return True

def main():
    K = int(input())
    A = [format(str(i),"0>5") for i in range(100000) if is_lunlun(i)]
    B = [int(a1+a2) for a1 in A for a2 in A if int(a1+a2) < 3234566668 and is_lunlun(int(a1+a2))]
    B2 = sorted(set(B))
    print(B2[K])

if __name__ == "__main__":
    main()
Buggy code:
def main():
    K = int(input())

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

    count = 0
    while True:
        count = count+1
        a = q.get()

        if count == K:
            break

        tail = int(str(a)[-1])
        for i in range(10):
            if abs(tail-i) > 1:
                continue
            q.put(int(str(a)+str(i)))

    print(a)

Fixed code:
import queue

def main():
    K = int(input())

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

    count = 0
    while True:
        count = count+1
        a = q.get()

        if count == K:
            break

        tail = int(str(a)[-1])
        for i in range(10):
            if abs(tail-i) > 1:
                continue
            q.put(int(str(a)+str(i)))

    print(a)

if __name__ == "__main__":
    main()