qyliang/CodeNanoFix huggingface dataset:
Buggy code:
k = int(input())
num = 0
for _ in range(k):
  num += 1
  digit = [int(digit) for digit in str(num)]
  len_digit = len(digit)
  flag = False
  for i in range(1, len_digit):
    # current_digit = digit[-i]
    # upper_digit = digit[-i-1]
    if digit[-i] > 9:
      digit[-i-1] += 1
      digit[-i] = -1
      flag = True
    elif digit[-i] > digit[-i-1] + 1:
      digit[-i-1] += 1
      digit[-i] = -1
      flag = True
    elif digit[-i] < digit[-i-1] - 1:
      digit[-i] = digit[-i-1] - 1
  if digit[0] > 9:
    num = 10 ** len_digit
  else:
    if flag:
      for i in range(1, len_digit):
        if digit[i] == -1:
          for j in range(i, len_digit):
            digit[j] = max(digit[j-1] - 1, 0)
          break
    num = 0
    for d in digit:
      num = num * 10 + d
print(num)

Fixed code:
k = int(input())
num = 0
for _ in range(k):
  num += 1
  digit = [int(digit) for digit in str(num)]
  len_digit = len(digit)
  flag = False
  for i in range(1, len_digit):
    # current_digit = digit[-i]
    # upper_digit = digit[-i-1]
    if digit[-i] == 10:
      digit[-i-1] += 1
      digit[-i] = -1
    elif digit[-i] > digit[-i-1] + 1:
      digit[-i-1] += 1
      digit[-i] = -1
    elif digit[-i] < digit[-i-1] - 1:
      digit[-i] = -1
  if digit[0] == 10:
    num = 10 ** len_digit
  else:
    for i in range(1, len_digit):
      if digit[i] == -1:
        for j in range(i, len_digit):
          digit[j] = max(digit[j-1] - 1, 0)
        break
    num = 0
    for d in digit:
      num = num * 10 + d
print(num)
Buggy code:
k=int(input())
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        z=int(x[-1])
        ans[-1].append(x+str(z))
        if z<=8:
            ans[-1].append(x+str(z+1))
        if z>=1:
            ans[-1].append(x+str(z-1))
    d+=len(ans[-1])
print(ans[-1][k-d-1])

Fixed code:
k=int(input())
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        z=int(x[-1])
        ans[-1].append(x+str(z))
        if z<=8:
            ans[-1].append(x+str(z+1))
        if z>=1:
            ans[-1].append(x+str(z-1))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print(v[k-(d-l)-1])
Buggy code:
k=int(input())
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        if z==0:
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        elif 1<=z<=8:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        else:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print(v[k-(d-l)-1])

Fixed code:
k=int(input())
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        y=int(x[0])
        if y==1:
            ans[-1].append(str(y)+x)
            ans[-1].append(str(y+1)+x)
        elif 2<=y<=8:
            ans[-1].append(str(y-1)+x)
            ans[-1].append(str(y)+x)
            ans[-1].append(str(y+1)+x)
        else:
            ans[-1].append(str(y-1)+x)
            ans[-1].append(str(y)+x)
        z=int(x[-1])
        if z==0:
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        elif 1<=z<=8:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        else:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
    ans[-1]=list(set(ans[-1]))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print(v[k-(d-l)-1])
Buggy code:
def main():
    k = int(input())
    hp = [i for i in range(k+4)]
    r, w = 1, 10
    while w < k:
        n = hp[r]
        r += 1
        nm = n % 10
        val = n * 10 + nm
        
        if nm != 0:
            hp[w] = val - 1
            w += 1
        hp[w] = val
        w += 1
        if nm != 9:
            hp[w] = val + 1
            w += 1

    print(hp[k])

main()


Fixed code:
def main():
    k = int(input())
    hp = [i for i in range(k+4)]
    r, w = 1, 10
    while w <= k:
        n = hp[r]
        r += 1
        nm = n % 10
        val = n * 10 + nm
        
        if nm != 0:
            hp[w] = val - 1
            w += 1
        hp[w] = val
        w += 1
        if nm != 9:
            hp[w] = val + 1
            w += 1

    print(hp[k])

main()
Buggy code:
def incr_lunlun(num):
    num[0] += 1
    if len(num) == 1:
        if num[0] == 10:
            num.append(1)
            num[0] = 0

    elif num[0] > num[1] + 1 or num[0] == 10:
        suffix = incr_lunlun(num[1:])
        num = [suffix[0] - 1] + list(suffix)

    return num


def main():
    k = int(input())
    num = [1]
    for i in range(k-1): 
        num = incr_lunlun(num)

    print(int(''.join(str(i) for i in reversed(num))))



main()


Fixed code:
def incr_lunlun(num):
    num[0] += 1
    if len(num) == 1:
        if num[0] == 10:
            num.append(1)
            num[0] = 0
    
    elif num[0] > num[1] + 1 or num[0] == 10:
        suffix = incr_lunlun(num[1:])
        digit = max(0, suffix[0] - 1)
        num = [digit] + list(suffix)

    return num


def main():
    k = int(input())
    num = [1]
    for i in range(k-1): 
        num = incr_lunlun(num)

    print(int(''.join(str(i) for i in reversed(num))))



main()
Buggy code:
from collections import deque

def main():
  	K = int(input())
    que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])

    while K:
        if K == 1:
            ans = que.popleft()
            break
        K -= 1
        v = que.popleft()
        if v[-1] == '0':
            que.append(v + '0')
            que.append(v + '1')
        elif v[-1] == '9':
            que.append(v + '8')
            que.append(v + '9')
        else:
            que.append(v + str(int(v[-1]) - 1))
            que.append(v + str(int(v[-1])))
            que.append(v + str(int(v[-1]) + 1))

    print(ans)

if __name__ == '__main__':
    main()

Fixed code:
from collections import deque
K = int(input())

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

while K:
    if K == 1:
        ans = que.popleft()
        break
    K -= 1
    v = que.popleft()
    if v[-1] == '0':
        que.append(v + '0')
        que.append(v + '1')
    elif v[-1] == '9':
        que.append(v + '8')
        que.append(v + '9')
    else:
        que.append(v + str(int(v[-1]) - 1))
        que.append(v + str(int(v[-1])))
        que.append(v + str(int(v[-1]) + 1))

print(ans)
Buggy code:
#!/usr/bin/env python3
k = int(input())
a = []
for i in range(1, 10):
    a.append(i)
while True:
    if k <= len(a):
        print(a[k - 1])
        exit()
    k -= len(a)
    old = []
    a, old = old, a
    for x in old:
        for i in range(-1, 2):
            d = x % 10 + i
            if d < 0 and d > 9:
                continue
            nx = x * 10 + d
            a.append(nx)


Fixed code:
#!/usr/bin/env python3
k = int(input())
a = []
for i in range(1, 10):
    a.append(i)
while True:
    if k <= len(a):
        print(a[k - 1])
        exit()
    k -= len(a)
    old = []
    a, old = old, a
    for x in old:
        for i in range(-1, 2):
            d = x % 10 + i
            if d < 0 or d > 9:
                continue
            nx = x * 10 + d
            a.append(nx)
Buggy code:
cur = []

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

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

Fixed code:
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]))
Buggy code:
from collections import deque

q=deque()

N=int(input())

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

for _ in range(N-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(q.poplefr())

Fixed code:
from collections import deque

q=deque()

N=int(input())

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

for _ in range(N-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(q.popleft())
Buggy code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K = ni() - 1

for le in range(1, 11):
    for h in range(1, 10):
        for a in itertools.product((-1, 0, 1), repeat=le-1):
            cur = h
            ok = True
            for u in a:
                cur += u
                if cur > 9 or cur < 0:
                    ok = False
                    break
            if ok:
                if K == 0:
                    ret = [h] + [_ + h for _ in itertools.accumulate(a)]
                    print("".join(map(str, ret)))
                    sys.exit(0)
                K -= 1

Fixed code:
import sys
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K = ni() - 1

for le in range(1, 11):
    for h in range(1, 10):
        for a in itertools.product((-1, 0, 1), repeat=le-1):
            cur = h
            ok = True
            for u in a:
                cur += u
                if cur > 9 or cur < 0:
                    ok = False
                    break
            if ok:
                if K == 0:
                    ret = [h] + [_ + h for _ in itertools.accumulate(a)]
                    print("".join(map(str, ret)))
                    sys.exit(0)
                K -= 1
Buggy code:
k = int(input())
cand = [[1,2,3,4,5,6,7,8,9]]
for i in range(9):
  tmp = []
  for val in cand[-1]:
    if val % 10 != 0:
      tmp.append(val*10 + (val%10 - 1))
    tmp.append(val*10 + (val % 10))
    if val % 10 != 9:
      tmp.append(val*10 + (val%10 + 1))
    cand.append(tmp)

ans = []
for j in range(len(cand)):
  for val in cand[i]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])

Fixed code:
k = int(input())
cand = [[1,2,3,4,5,6,7,8,9]]
for i in range(9):
  tmp = []
  for val in cand[-1]:
    if val % 10 != 0:
      tmp.append(val*10 + (val%10 - 1))
    tmp.append(val*10 + (val % 10))
    if val % 10 != 9:
      tmp.append(val*10 + (val%10 + 1))
  cand.append(tmp)

ans = []
for j in range(len(cand)):
  for val in cand[j]:
    ans.append(val)
ans = sorted(ans)

print(ans[k - 1])
Buggy code:
import queue
k = int(input())
q = [1,2,3,4,5,6,7,8,9]
qq = queue.Queue()
for i in range(1,10):
	qq.put(i)

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

Fixed code:
import queue
k = int(input())
q = [1,2,3,4,5,6,7,8,9]
qq = queue.Queue()
for i in range(1,10):
	qq.put(i)

for i in range(k):
	x = qq.get()
	if x%10 != 0:
		qq.put(10*x + (x%10) -1)
	qq.put(10*x + (x%10))
	if x%10 != 9:
		qq.put(10*x + (x%10) +1)
		
print(x)
Buggy code:
import queue

k = int(input())
q = queue.Queue()
x = -1
for i in range(1,10):
    q.put(i)
for i in range(1,k+1):
    x = q.get()
    if x % 10 != 0:
        q.put(10 * x + (x % 10) - 1)
    q.put(10 * x + (x % 10))
    if x % 9 != 0:
        q.put(10 * x + (x % 10) + 1)
print(x)

Fixed code:
import queue

k = int(input())
q = queue.Queue()
x = -1
for i in range(1,10):
    q.put(i)
for i in range(1,k+1):
    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)
print(x)
Buggy code:
import queue
K = int( input() )

q = queue.Queue()

ret = K
for i in range( 1, 9 + 1 ):
  q.put( i )

number_of_operations = 9
while number_of_operations < K:
  i = q.get()
  k = i % 10 
  if k != 0:
    ret = 10 * i + k - 1
    q.put( ret )
    number_of_operations += 1
  ret = 10 * i + k
  q.put( ret )
  number_of_operations += 1
  if k != 9:
    ret = 10 * i + k + 1
    q.put( ret )
    number_of_operations += 1

print( ret )

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

q = queue.Queue()

ret = K
number_of_operations = 9
for i in range( 1, number_of_operations + 1 ):
  q.put( i )

while number_of_operations < K:
  i = q.get()
  k = i % 10 
  if k != 0:
    ret = 10 * i + k - 1
    q.put( ret )
    number_of_operations += 1
    if number_of_operations == K:
      break
  ret = 10 * i + k
  q.put( ret )
  number_of_operations += 1
  if number_of_operations == K:
    break

  if k != 9:
    ret = 10 * i + k + 1
    q.put( ret )
    number_of_operations += 1

print( ret )
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()
    if not x%10 == 0:
        q.put(10*x+(x%10)-1)
    q.put(10*x+(x%10))
    if not x%10 == 9:
        q.put(10*x+(x%10)+1)

print(x)


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()
    if not x%10 == 0:
        q.put(10*x+(x%10)-1)
    q.put(10*x+(x%10))
    if not x%10 == 9:
        q.put(10*x+(x%10)+1)

print(x)
Buggy code:
lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = int(input())
index = 0
while True:
	if len(lun_luns) >= k:
		break
	num = lun_luns.pop(index)
	lun_luns.insert(index, num)
	mod = num % 10
	n = num * 10
	if mod == 9:
		lun_luns.extend([n+mod-1, n+mod])
	else:
		lun_luns.extend([n+mod-1, n+mod, n+mod+1])
	index += 1
print(lun_luns[k-1])

Fixed code:
lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = int(input())
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
print(lun_luns[k-1])
Buggy code:
import sys
from collections import deque
input = sys.stdin.readline

n=int(input())
L=deque(list(range(1,10)))
if n<=9:
    ans = L[n-1]
else:
    cnt = 9
    for i in range(1,n):
        c=L.popleft()
        
        if c%10!=0:
            L.append(c*10+(c%10)-1)
            cnt+=1
            if cnt>=n:
                break
        L.append(c*10+(c%10))
        cnt+=1
        if cnt>=n:
            break
        
        if c%10!=9:
            L.append(c*10+(c%10)+1)
            cnt+=1
            if cnt>=n:
                break
        print(L)
    ans = L[-1]
print(ans)


Fixed code:
import sys
from collections import deque
input = sys.stdin.readline

n=int(input())
L=deque(list(range(1,10)))
if n<=9:
    ans = L[n-1]
else:
    cnt = 9
    for i in range(1,n):
        c=L.popleft()
        
        if c%10!=0:
            L.append(c*10+(c%10)-1)
            cnt+=1
            if cnt>=n:
                break
        L.append(c*10+(c%10))
        cnt+=1
        if cnt>=n:
            break
        
        if c%10!=9:
            L.append(c*10+(c%10)+1)
            cnt+=1
            if cnt>=n:
                break
    ans = L[-1]
print(ans)
Buggy code:
k = int(input())
lunlun = list(range(1, 10))

for i in range(k - 1):
    a = lunlun[i]
    b = a * 10 + a % 10
    if a % 10 != 0:
        lunlun.append(b - 1)
    lunlun.append(b)
    if a % 10 != 9:
        lunlun.append(b + 1)
print(lunlun)
print(lunlun[k - 1])

Fixed code:
k = int(input())
lunlun = list(range(1, 10))
 
for i in range(k-1):
    a = lunlun[i]
    b = a * 10 +  a % 10 
    if a % 10 != 0:
        lunlun.append(b - 1)
    lunlun.append(b)
    if a % 10 != 9:
        lunlun.append(b + 1)
 
print(lunlun[k-1])
Buggy code:
k=int(input())
s=9
l=[1,2,3,4,5,6,7,8,9]
n=0
while s<10**5+1:
  t=l[n]
  z=int(str(t)[-1])
  l.append(t*10+z-1)
  l.append(t*10+z)
  s+=2
  if z<9:
    l.append(t*10+z+1)
    s+=1
  n+=1
l.sort()
print(l[k-1])

Fixed code:
k=int(input())
s=9
l=[1,2,3,4,5,6,7,8,9]
n=0
while s<10**5+1:
  t=l[n]
  z=int(str(t)[-1])
  if z>0:  
    l.append(t*10+z-1)
    s+=1
  l.append(t*10+z)
  s+=1
  if z<9:
    l.append(t*10+z+1)
    s+=1
  n+=1
l.sort()
print(l[k-1])
Buggy code:
K = int(input())
table = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
c = 9
result = []
for i in table:
  runrun = i
  if runrun[-1] == '0':
    table.extend([runrun + str(int(runrun)), 
                   runrun + str(int(runrun)+1)])
    c += 2
  elif runrun[-1] == '9':
    table.extend([runrun + str(int(runrun)-1), 
                   runrun + str(int(runrun))])
    c += 2
  else:
    table.extend([runrun + str(int(runrun)-1), 
                   runrun + str(int(runrun)), 
                   runrun + str(int(runrun)+1)])
    c += 3
  if c>=K:
    print(table[K-1])
    exit()

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

lun = []
for i in range(1,10):
    lun.append(i)

if k <= 9:
    print(lun[k-1])
    exit()

prev_lun = deepcopy(lun)
while True:
    for pl in prev_lun:
        for i in [-1, 0, 1]:
            d = pl%10 + i
            if not 0 <= d <= 9:
                continue
            lun.append(pl*10 + d)
            if len(lun) == k:
                print(lun[k-1])
                exit()
                
    prev_lun = []


Fixed code:
from copy import deepcopy
k = int(input())

lun = []
for i in range(1,10):
    lun.append(i)

if k <= 9:
    print(lun[k-1])
    exit()

prev_lun = deepcopy(lun)

while True:
    size = len(lun)
    for pl in prev_lun:
        for i in [-1, 0, 1]:
            d = pl%10 + i
            if 0 <= d <= 9:
                lun.append(pl*10 + d)
            if len(lun) == k:
                # print(lun)
                print(lun[k-1])
                exit()
                
    prev_lun = deepcopy(lun[size:])
Buggy code:
k = int(input())
old = [1,2,3,4,5,6,7,8,9]
new = []
count = 9
if k <= count:
    print(ans[k])
while count < k:
    if len(old) > 0:
        i = old.pop(0)
        last = i%10
        if last != 0:
            new.append(i*10 + (last-1))
            count += 1
            if count == k:
                break
        new.append(i*10 + last)
        count += 1
        if count == k:
            break
        if last != 9:
            new.append(i*10 + (last+1))
            count += 1
            if count == k:
                break
    else:
        old = new
        new = []
print(new[-1])

Fixed code:
import sys
k = int(input())
old = [1,2,3,4,5,6,7,8,9]
new = []
count = 9
if k <= count:
    print(old[k-1])
    sys.exit()
else:
    while count < k:
        if len(old) > 0:
            i = old.pop(0)
            last = i%10
            if last != 0:
                new.append(i*10 + (last-1))
                count += 1
                if count == k:
                    break
            new.append(i*10 + last)
            count += 1
            if count == k:
                break
            if last != 9:
                new.append(i*10 + (last+1))
                count += 1
                if count == k:
                    break
        else:
            old = new
            new = []
    print(new[-1])
Buggy code:
K = 12
table = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in table:
  if len(table) > K:
    break
  x = i % 10
  for j in range(max(0, x - 1), min(x + 2, 10)):
    table.append(i * 10 + j)

print(table[K-1])

Fixed code:
K = int(input())
table = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in table:
  if len(table) > K:
    break
  x = i % 10
  for j in range(max(0, x - 1), min(x + 2, 10)):
    table.append(i * 10 + j)
print(table[K-1])
Buggy code:
def update_queue(queue):
    out = queue.pop(0)
    mod10 = out % 10
    if mod10 != 0:
        queue.append(10 * out + mod10 - 1)
    queue.append(10 * queue + mod10)
    if mod10 != 9:
        queue.append(10 * out + mod10 + 1)

    return out, queue

N = int(input())
Q = [1,2,3,4,5,6,7,8,9]

for _ in range(N):
    out, Q = update_queue(Q)

print(out)

Fixed code:
def update_queue(n, queue):
    out = queue[n]
    mod10 = out % 10
    if mod10 != 0:
        queue.append(10 * out + mod10 - 1)
    queue.append(10 * out + mod10)
    if mod10 != 9:
        queue.append(10 * out + mod10 + 1)

    return out, queue

N = int(input())
Q = [1,2,3,4,5,6,7,8,9]

for i in range(N):
    out, Q = update_queue(i, Q)

print(out)
Buggy code:
a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]
import heapq
heapq.heapify(a)
cnt = 18
c = 1
while True:
  if cnt > 10**5:
    break
  for i in a:
    if len(str(i)) == c:
      m = i//10**(c-1)
      if i//10**(c-1) == 1:
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 2
        for j in range(10-c):
          heapq.heappush(a,i+10**c*(10**(j+1)))
          cnt += 1
      elif i//10**(c-1) == 9:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        cnt += 2
      else:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
  c += 1

k = int(input())
#a = set(a)
#a = list(a)
for i in range(k):
  heapq.heappop(a)
print(heapq.heappop(a))

Fixed code:
a = [1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]
import heapq
heapq.heapify(a)
cnt = 18
c = 1
while True:
  if cnt > 10**5:
    break
  for i in a:
    if len(str(i)) == c:
      m = i//10**(c-1)
      if i//10**(c-1) == 1:
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 2
        for j in range(10-c):
          heapq.heappush(a,i+10**c*(10**(j+1)))
          cnt += 1
      elif i//10**(c-1) == 9:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        cnt += 2
      else:
        heapq.heappush(a,i+10**c*(i//10**(c-1)-1))
        heapq.heappush(a,i+10**c*(i//10**(c-1)))
        heapq.heappush(a,i+10**c*(i//10**(c-1)+1))
        cnt += 3
  c += 1

k = int(input())
#a = set(a)
#a = list(a)
for i in range(k-1):
  heapq.heappop(a)
print(heapq.heappop(a))
Buggy code:
# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    seen.append(value)
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)

Fixed code:
# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)