qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import deque
K = int(input())
ans = 0
cnt = 9
start = 0
X = deque([[[9],[8],[7],[6],[5],[4],[3],[2],[1]]])
for _ in range(10000):
    X.append(deque([]))
for i in range(1,10000):
    now_cnt = cnt
    for x in list(X[i-1]):
        for j in range(10,0,-1):
            if abs(x[len(x)-1]-j+1) <= 1:
                X[i].append(x+[j-1])
                cnt += 1
    if cnt >= K:
        X[i].reverse()
        lun = X[i][K-now_cnt-1]
        
        N = []
        
        for n in lun:
          N.append(str(n))
        
        print(''.join(N))
        exit()

Fixed code:
from collections import deque
K = int(input())
ans = 0
cnt = 9
start = 0
X = deque([[[9],[8],[7],[6],[5],[4],[3],[2],[1]]])
if K <= 9:
  print(K)
  exit()
for _ in range(10000):
    X.append(deque([]))
for i in range(1,10000):
    now_cnt = cnt
    for x in list(X[i-1]):
        for j in range(10,0,-1):
            if abs(x[len(x)-1]-j+1) <= 1:
                X[i].append(x+[j-1])
                cnt += 1
    if cnt >= K:
        X[i].reverse()
        lun = X[i][K-now_cnt-1]
        
        N = []
        
        for n in lun:
          N.append(str(n))
        
        print(''.join(N))
        exit()
Buggy code:
from collections import deque


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

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

Fixed code:
from collections import deque
 
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
 
for i in range(k):
  a = q.popleft()
  if a % 10 == 0:
    q.append(10*a)
    q.append(10*a + 1)
  elif a % 10 == 9:
    q.append(10*a + 8)
    q.append(10*a + 9)
  else:
    q.append(10*a + a%10 - 1)
    q.append(10*a + a%10)
    q.append(10*a + a%10 + 1)
else:
  print(a)
Buggy code:
# 2020/04/04
# AtCoder Beginner Contest 161 - D

runsu = list()

def makerunrun(s):

    if int(s) > 3234566667:
        return 0

    runsu.append(int(s))
    lketa = int(s[len(s)-1])
    if lketa > 0:
        wks = s + str(lketa - 1)
        makerunrun(wks)
    
    wks = s + str(lketa)
    makerunrun(wks)
    
    if lketa < 10:
        wks = s + str(lketa + 1)
        makerunrun(wks)
    
# Input
k = int(input())

# Make Runrun List
for i in range(1, 10):
    makerunrun(str(i))

runsu.sort()

for i in range(500):
    print(runsu[i])

# Output
print(runsu[k-1])


Fixed code:
# 2020/04/04
# AtCoder Beginner Contest 161 - D

runsu = list()

def makerunrun(s):

    if int(s) > 3234566667:
        return 0

    runsu.append(int(s))
    lketa = int(s[len(s)-1])
    if lketa > 0:
        wks = s + str(lketa - 1)
        makerunrun(wks)
    
    wks = s + str(lketa)
    makerunrun(wks)
    
    if lketa < 9:
        wks = s + str(lketa + 1)
        makerunrun(wks)
    
# Input
k = int(input())

# Make Runrun List
for i in range(1, 10):
    makerunrun(str(i))

runsu.sort()

# Output
print(runsu[k-1])
Buggy code:
def dfs(r):
    global l
    if len(r) == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(str(i))
print(sorted(l)[k])

Fixed code:
def dfs(r):
    global l
    if len(r) == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(str(i))
print(sorted(l)[k - 1])
Buggy code:
#!/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])

Fixed code:
#!/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])
Buggy code:
k=int(input())
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

f(0,0,L)
print(L[k-1])
      

Fixed code:
k=int(input())
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

for l in range(1,10):
  f(1,l,L)
L.sort()
print(L[k-1])
Buggy code:
k = int(input()) 
 
 lunlun = [i for i in range(1, 10)]
 
 p = 0 

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

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

print(lunlun[k-1])

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

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

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

print(lunlun[k-1])
Buggy code:
from collections import deque
k=int(input())
d=deque([1,2,3,4,5,6,7,8,9])
for i in range(k):
  x=d.popleft()
  if x%10!=0:
    d.append(10*x+x-1)
  d.append(10*x+x)
  if x%10!=9:
    d.append(10*x+x+1)
print(x)

Fixed code:
from collections import deque
k=int(input())
d=deque([1,2,3,4,5,6,7,8,9])
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:
rom collections import deque
 
K = int(input())
que = deque([i for i in range(1, 10)])
lunlun = []
 
while que:
    num = que.pop()
    lunlun.append(num)
    for i in range(10):
        if abs(int(str(num)[-1]) - i) <= 1:
            cand = int(str(num) + str(i))
            if cand < 10000000000:
                que.append(cand)
 
lunlun.sort()
print(sorted(lunlun)[K - 1])

Fixed code:
from collections import deque

K = int(input())
que = deque([i for i in range(1, 10)])
lunlun = []

while que:
    num = que.pop()
    lunlun.append(num)
    for i in range(10):
        if abs(int(str(num)[-1]) - i) <= 1:
            cand = int(str(num) + str(i))
            if cand < 10000000000:
                que.append(cand)

lunlun.sort()
print(sorted(lunlun)[K - 1])
Buggy code:
from collections import deque


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

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

print(a)




Fixed code:
from collections import deque


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

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

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

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

ans = 1
cnt = 0
while cnt < k:
    # print(ans, cnt)
    if ans <= 9:
        cnt+=1
        ans+=1
        continue
    li = list(map(int, list(str(ans))))
    flag=1
    for i in range(len(li)-1):
        if abs(li[i]-li[i+1]) > 1:
            ans+=1
            flag=0
            break
    if flag:
        cnt+=1
        ans+=1
print(ans-1)

Fixed code:
k = int(input())

ans = 1
cnt = 0
while cnt < k:
    # print(ans, cnt)
    if ans <= 9:
        cnt+=1
        ans+=1
        continue
    li = list(map(int, list(str(ans))))
    flag=1
    for i in range(len(li)-1):
        if abs(li[i]-li[i+1]) > 1:
            ans+=10**(len(li)-i-2)
            flag=0
            break
    if flag:
        cnt+=1
        ans+=1
print(ans-1)
Buggy code:
k = int(input())

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

c = 0
while k>len(l):
    f = str(l[c])

    if f[-1]!=0:
        l.append(int(f)*10 + int(f[-1])-1)

    l.append(int(f)*10 + int(f[-1]))

    if f[-1]!=9:
        l.append(int(f)*10 + int(f[-1])+1)

    c += 1
print(l[k-1])

Fixed code:
k = int(input())

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

c = 0
while k>len(l):
    f = str(l[c])

    if int(f[-1])!=0:
        l.append(int(f)*10 + int(f[-1])-1)

    l.append(int(f)*10 + int(f[-1]))

    if int(f[-1])!=9:
        l.append(int(f)*10 + int(f[-1])+1)

    c += 1

print(l[k-1])
Buggy code:
K = int(input())
lunlun = [n for n in range(10)]
if K < 10:
    print(K)
else:
    tmp = 9
    pre_top = 1
    pre_bottom = 9
    while(1):
        for j in range(pre_top, pre_bottom+1):
            for k in range(10):
                if abs(lunlun[j]%10 - k) < 2:
                    lunlun.append(lunlun[j]*10+k)
                    tmp += 1
                    if tmp == K:
                        break
            if tmp == K:
                break
        pre_top = pre_bottom + 1
        pre_bottom = tmp
        if tmp == K:
            break

print(lunlun[-1])

Fixed code:
K = int(input())
lunlun = [n for n in range(10)]
if K < 10:
    print(K)
else:
    tmp = 9
    pre_top = 1
    pre_bottom = 9
    while(1):
        for j in range(pre_top, pre_bottom+1):
            for k in range(10):
                if abs(lunlun[j]%10 - k) < 2:
                    lunlun.append(lunlun[j]*10+k)
                    tmp += 1
                    if tmp == K:
                        break
            if tmp == K:
                break
        pre_top = pre_bottom + 1
        pre_bottom = tmp
        if tmp == K:
            break

    print(lunlun[-1])
Buggy code:
k = int(input())
ans = [str(i) for i in range(1,10)]
c = 0
while len(ans)!=k:
    now = ans[c]
    t = int(now[-1])
    if t != 0:
        ans.append(str(now) +str(t-1))

    ans.append(str(now) +str(now)[-1])

    if t != 9:
        ans.append(str(now) +str(t+1))

    c += 1
print(ans[k-1])

Fixed code:
k = int(input())
ans = [str(i) for i in range(1,10)]
c = 0

while len(ans) < k:
    now = ans[c]
    t = int(now[-1])
    if t != 0:
        ans.append(str(now) +str(t-1))

    ans.append(str(now) +str(now)[-1])

    if t != 9:
        ans.append(str(now) +str(t+1))

    c += 1
print(ans[k-1])
Buggy code:
from collections import deque

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


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

Fixed code:
from collections import deque

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

for i in range(K-1):
    j = a.popleft()
    if j%10 != 0:
        a.append((10*j) + ((j%10) -1))
        
    a.append((10*j)+j%10)
    
    if j%10 != 9:
        a.append((10*j) +((j%10)+1))
    
print(a.popleft())
Buggy code:
n = int(input())
lunlun = [[1,2,3,4,5,6,7,8,9]]

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

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

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

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


def get_lunlun(K):
    for num in queue:
        if len(queue) >= K:
            return queue[-1]
        for i in range(-1, 2):
            last = num % 10 + i
            if last < 0 or last > 9:
                continue
            queue.append(num * 10 + last)


print(get_lunlun(K))

Fixed code:
K = int(input())

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


def get_lunlun(K):
    for num in queue:
        if len(queue) >= K:
            return queue[K - 1]
        for i in range(-1, 2):
            last = num % 10 + i
            if last < 0 or last > 9:
                continue
            queue.append(num * 10 + last)


print(get_lunlun(K))
Buggy code:
def count_lunlun(num):
    num = list(map(int, str(num)))
    d = len(num)
    dp = [[[[0] * 10 for _ in range(2)] for _ in range(2)] for _ in range(d + 1)]
    dp[0][0][0][0] = 1
    for i in range(d):
        for j in range(2):
            for k in range(10):
                for z in range(2):
                    for x in range(10 if j else (num[i] + 1)):
                        if abs(x - k) <= 1:
                            dp[i + 1][j or x < num[i]][x != 0][x] += dp[i][j][z][k]
                        elif z == 0:
                            dp[i + 1][j or x < num[i]][x != 0][x] += dp[i][j][z][k]
    return sum(dp[d][0][0]) + sum(dp[d][0][1]) + sum(dp[d][1][0]) + sum(dp[d][1][1]) - 1


K = int(input())
left = 0
right = 10 ** 12
while right - left > 1:
    mid = (left + right) // 2
    count = count_lunlun(mid)
    if count >= K:
        right = mid
    else:
        left = mid
print(right)

Fixed code:
def count_lunlun(num):
    num = list(map(int, str(num)))
    d = len(num)
    dp = [[[[0] * 10 for _ in range(2)] for _ in range(2)] for _ in range(d + 1)]
    dp[0][0][0][0] = 1
    for i in range(d):
        for j in range(2):
            for k in range(10):
                for z in range(2):
                    for x in range(10 if j else (num[i] + 1)):
                        if abs(x - k) <= 1:
                            dp[i + 1][j or x < num[i]][x != 0 or z][x] += dp[i][j][z][k]
                        elif z == 0:
                            dp[i + 1][j or x < num[i]][x != 0 or z][x] += dp[i][j][z][k]
    return sum(dp[d][0][0]) + sum(dp[d][0][1]) + sum(dp[d][1][0]) + sum(dp[d][1][1]) - 1


K = int(input())
left = 0
right = 10 ** 12
while right - left > 1:
    mid = (left + right) // 2
    count = count_lunlun(mid)
    if count >= K:
        right = mid
    else:
        left = mid
print(right)
Buggy code:
k = int(input())

dp = [[[] for j in range(11)] for i in range(11)]

for i in range(10):
    dp[1][i].append(i)

for i in range(11):
    dp[i][0].append(0)


if k<=9:
    print(k)
    exit()

k-=9

for i in range(2, 11):
    for j in range(1, 10):
        for x in dp[i-1][j-1]:
            dp[i][j].append(j*10**(i-1)+x)
            k-=1
            if k==0:
                print(dp[i][j][-1])
                exit()
        for x in dp[i - 1][j]:
            dp[i][j].append(j * 10 ** (i-1) + x)
            k-=1
            if k==0:
                print(dp[i][j][-1])
                exit()
        for x in dp[i - 1][j + 1]:
            dp[i][j].append(j * 10 ** (i-1) + x)
            k-=1
            if k==0:
                print(dp[i][j][-1])
                exit()




Fixed code:
k = int(input())

dp = [[[] for j in range(11)] for i in range(11)]


for i in range(10):
    dp[1][i].append(i)
    dp[0][i].append(0)


if k<=9:
    print(k)
    exit()

k-=9

for i in range(2, 11):
    for j in range(1, 10):
        if j==1:
            for z in range(i):
                for x in dp[z][j]:
                    dp[i][j].append(j*10**(i-1)+x)
                    k-=1
                    if k==0:
                        print(dp[i][j][-1])
                        exit()
            for x in dp[i - 1][j + 1]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
        else:
            for x in dp[i-1][j-1]:
                dp[i][j].append(j*10**(i-1)+x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
            for x in dp[i - 1][j]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
            for x in dp[i - 1][j + 1]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
Buggy code:
k = int(input())
L = []

def lunlun(d,v,L):
    L.append(v)
    if d == 4:
        return
    for i in range(-1,2):
        t = v%10 + i
        #print(v)
        if 0 <= t <=9:
            lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
    lunlun(1,v,L)
print(sorted(L)[k-1])

Fixed code:
k = int(input())
L = []

def lunlun(d,v,L):
    L.append(v)
    if d == 10:
        return
    for i in range(-1,2):
        t = v%10 + i
        #print(v)
        if 0 <= t <=9:
            lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
    lunlun(1,v,L)
print(sorted(L)[k-1])
Buggy code:
k = int(input())

L = [1,2,3,4,5,6,7,8,9]
i = 0
while i < k:
    if int(str(L[i])[-1]) == 1:
        n1 = L[i]*10 
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif 2 <= int(str(L[i])[-1]) <= 8:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif int(str(L[i])[-1]) == 9:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        L.append(n1)
        L.append(n2)
    i +=1
print(L[k-1])

Fixed code:
k = int(input())
L = [1,2,3,4,5,6,7,8,9]
i = 0
while i < k:
    if int(str(L[i])[-1]) == 0:
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n2)
        L.append(n3)
    elif 1 <= int(str(L[i])[-1]) <= 8:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif int(str(L[i])[-1]) == 9:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        L.append(n1)
        L.append(n2)
    i +=1

print(L[k-1])
Buggy code:
import collections
k=int(input())
if k<=9:
    print(k)
else:
    k-=9
    l =list(range(9,0,-1))
    print(l)
    q = collections.deque(l)
    counter=0
    while counter<k:
        x=q.pop()
        xrem=x%10
        if xrem!=0:
            q.appendleft(10*x+xrem-1)
            counter+=1
            if counter>=k:
                break
        q.appendleft(10*x+xrem)
        counter+=1
        if counter>=k:
                break
        if xrem!=9:
            q.appendleft(10*x+xrem+1)
            counter+=1
    print(q[0])


Fixed code:
import collections
k=int(input())
if k<=9:
    print(k)
else:
    k-=9
    l =list(range(9,0,-1))
    #print(l)
    q = collections.deque(l)
    counter=0
    while counter<k:
        x=q.pop()
        xrem=x%10
        if xrem!=0:
            q.appendleft(10*x+xrem-1)
            counter+=1
            if counter>=k:
                break
        q.appendleft(10*x+xrem)
        counter+=1
        if counter>=k:
                break
        if xrem!=9:
            q.appendleft(10*x+xrem+1)
            counter+=1
    print(q[0])
Buggy code:
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())

Fixed code:
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 + d % 10 - 1)
    q.append(10 * d + d % 10)
    if d % 10 != 9:
        q.append(10 * d + d % 10 +1)
    
print(q.popleft())
Buggy code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()


q = queue.Queue()

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

n = readInt()

for i in range(1,100000):
	a = str(q.get())
	if a[-1]!=0:
		q.put(int(a+str(int(a[-1])-1)))
	q.put(int(a+str(str(int(a[-1])))))
	if a[-1]!=9:
		q.put(int(a+str(int(a[-1])+1)))	
	if i==n:
		print(q.get())
		break

Fixed code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()


q = queue.Queue()

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

n = readInt()

for i in range(1,100001):
	a = str(q.get())
	b = int(a[-1])
	if b!=0:
		q.put(int(a+str(b-1)))
	q.put(int(a+str(b)))
	if b!=9:
		q.put(int(a+str(b+1)))	
	if i==n:
		print(int(a))
		break
Buggy code:
def jud(n1,n2):
	if abs(n1-int(str(n2)[0]))<=1:
		return 1
	else:
		return 0

rnrn = [[1,2,3,4,5,6,7,8,9],[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99]]

for div in range(1,12):
	rnrn.append([])
	for i in range(len(rnrn[div])):
		y = str(rnrn[div][i])
		x = int(y[-1])
		if x-1!=-1:
			rnrn[div+1].append(int(y+str(x-1)))
		rnrn[div+1].append(int(y+str(x)))
		if x+1!=10:
			rnrn[div+1].append(int(y+str(x+1)))
		
rnrn2 = []
for i in range(len(rnrn)):
	rnrn2.extend(rnrn[i])

print(rnrn2[int(input())])

Fixed code:
def jud(n1,n2):
	if abs(n1-int(str(n2)[0]))<=1:
		return 1
	else:
		return 0

rnrn = [[1,2,3,4,5,6,7,8,9],[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99]]

for div in range(1,10):
	rnrn.append([])
	for i in range(len(rnrn[div])):
		y = str(rnrn[div][i])
		x = int(y[-1])
		if x-1!=-1:
			rnrn[div+1].append(int(y+str(x-1)))
		rnrn[div+1].append(int(y+str(x)))
		if x+1!=10:
			rnrn[div+1].append(int(y+str(x+1)))
		
rnrn2 = []
for i in range(len(rnrn)):
	rnrn2.extend(rnrn[i])

print(rnrn2[int(input())-1])