qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import deque


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

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

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

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

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

    print('answer:', n)


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


Fixed code:
from collections import deque


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

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

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

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

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

    print(n)


##########
if __name__ == "__main__":
    lunlun()
Buggy code:
def d():
    k = int(input())

    val = 0
    hits = 0
    hit_tails = {}
    while hits < k:
        val += 1
        if len(str(val)) == 1:
            hits += 1
            hit_tails[val] = int(str(val)[-1])
            # print('====', hits, val)
            pass
        else:
            lst = list(map(int, str(val)))
            for i in range(len(lst) - 1):
                if lst[i] > lst[i+1] + 1:
                    lst[i+1] = lst[i] - 2
                    if(i < len(lst) - 2):
                        lst[i+2:] = [9] * (len(lst) - 2)
                    val = int(''.join(map(str, lst)))
                    break
                elif lst[i] < lst[i+1] - 1:
                    lst[i+1:] = [9] * (len(lst) - 1)
                    val = int(''.join(map(str, lst)))
                    break
                elif i == len(lst) - 2:
                    hits += 1
                    hit_tails[val] = int(str(val)[-1])
                    # print('====', hits, val)
                    pass

    print(val)


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


Fixed code:
def d():
    k = int(input())

    val = 0
    hits = 0
    hit_tails = {}
    while hits < k:
        val += 1
        if len(str(val)) == 1:
            hits += 1
            hit_tails[val] = int(str(val)[-1])
            # print('====', hits, val)
            pass
        else:
            lst = list(map(int, str(val)))
            # print('before:', lst)
            for i in range(len(lst) - 1):
                if lst[i] > lst[i+1] + 1:
                    lst[i+1] = lst[i] - 2
                    if(i < len(lst) - 2):
                        lst[i+2:] = [9] * len(lst[i+2:])
                    val = int(''.join(map(str, lst)))
                    # print('after1:', lst)
                    break
                elif lst[i] < lst[i+1] - 1:
                    lst[i+1:] = [9] * len(lst[i+1:])
                    val = int(''.join(map(str, lst)))
                    # print('after2:', lst)
                    break
                elif i == len(lst) - 2:
                    hits += 1
                    hit_tails[val] = int(str(val)[-1])
                    # print('====', hits, val)
                    pass

    print(val)


##########
if __name__ == "__main__":
    d()
Buggy code:
K = int(input())

queue = list(range(1, 10))

if K <= 10:
    print(K)
else:
    i = 0
    while K > len(queue):
        if queue[i] % 10 != 0:
            l = 10 * queue[i] + queue[i] % 10 - 1
            queue.append(l)
        
        l = 10 * queue[i] + queue[i] % 10
        queue.append(l)
        
        if queue[i] % 10 != 9:
            l = 10 * queue[i] + queue[i] % 10 + 1
            queue.append(l)
        
        i += 1

    print(queue[-1])

Fixed code:
K = int(input())

queue = list(range(1, 10))

if K < 10:
    print(K)
else:
    i = 0
    while K > len(queue):
        if queue[i] % 10 != 0:
            l = 10 * queue[i] + queue[i] % 10 - 1
            queue.append(l)
        
        l = 10 * queue[i] + queue[i] % 10
        queue.append(l)
        
        if queue[i] % 10 != 9:
            l = 10 * queue[i] + queue[i] % 10 + 1
            queue.append(l)
        
        i += 1

    print(queue[K - 1])
Buggy code:
from collections import deque

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

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

print(q.pop())

Fixed code:
from collections import deque

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

for i in range(1,k):
    l = q.popleft()
    if (len(q) < k):
        m = l % 10
        if (m != 0):
            q.append(l * 10 + m - 1)
        q.append(l * 10 + m)
        if (m != 9):
            q.append(l * 10 + m + 1)

print(q.popleft())
Buggy code:
import queue
import time
import sys
input = sys.stdin.readline


def main():
    K = int(input().strip())
    que = queue.Queue()
    [que.put(i) for i in range(1, 10)]
    for _ in range(K):
        answer = que.get()
        if answer % 10 != 0:
            que.put(10*answer + answer-1)
        que.put(10 * answer + answer)
        if answer % 10 != 9:
            que.put(10*answer + answer + 1)
    print(answer)


if __name__ == '__main__':
    main()


Fixed code:
import queue
import time
import sys
input = sys.stdin.readline


def main():
    K = int(input().strip())
    que = queue.Queue()
    [que.put(i) for i in range(1, 10)]
    for _ in range(K):
        answer = que.get()
        if answer % 10 != 0:
            que.put(10*answer + answer % 10 - 1)
        que.put(10 * answer + answer % 10)
        if answer % 10 != 9:
            que.put(10*answer + answer % 10 + 1)
    print(answer)


if __name__ == '__main__':
    main()
Buggy code:
import queue

k = int(input())
q = queue.Queue()
for l in range(10)[1:]:
    q.put(l)
if k < 10:
    print(q.queue[k])
k -= 9
for l in range(k):
    dequeued = q.get()
    mod = dequeued % 10
    if mod != 0:
        q.put(dequeued * 10 + mod - 1)
    q.put(dequeued * 10 + mod)
    if mod != 9:
        q.put(dequeued * 10 + mod + 1)
print(q.queue[8])

Fixed code:
import queue

k = int(input())
q = queue.Queue()
for l in range(10)[1:]:
    q.put(l)
if k < 10:
    print(q.queue[k-1])
    exit()
k -= 9
for l in range(k):
    dequeued = q.get()
    mod = dequeued % 10
    if mod != 0:
        q.put(dequeued * 10 + mod - 1)
    q.put(dequeued * 10 + mod)
    if mod != 9:
        q.put(dequeued * 10 + mod + 1)
print(q.queue[8])
Buggy code:
from collections import deque
K=int(input())
d=deque([_ for _ in range(1,10)])
if K<=9:
  print(K)
  exit()
i=0
while True:
  a=d.pop()
  i+=1
  if i==K:
    print(a)
    exit()
  if a%10!=0 and a%10!=9:
    d.extend([10*a+(a%10)+i for i in range(-1,2)])
  elif a%10==0:
     d.extend([10*a+i for i in range(2)])
  else:
     d.extend([10*a+i for i in range(-1,2)])

Fixed code:
from collections import deque
K=int(input())
d=deque([_ for _ in range(1,10)])
if K<=9:
  print(K)
  exit()
i=0
while True:
  a=d.popleft()
  i+=1
  if i==K:
    print(a)
    exit()
  if a%10!=0 and a%10!=9:
    d.extend([10*a+(a%10)+i for i in range(-1,2)])
  elif a%10==0:
     d.extend([10*a+i for i in range(2)])
  elif a%10==9:
     d.extend([10*a+i for i in range(8,10)])
Buggy code:
from collections import deque
k = int(input())
a = deque([1,2,3,4,5,6,7,8,9])
count=0
while count !=k:
  b = a.popleft()
  count += 1
  if b%10==0:
    a.append(b*10)
    a.append(b*10+1)
  elif b%9==0:
    a.append(b*11-1)
    a.append(b*10+9)
  else:
    a.append(b*10+b%10-1)
    a.append(b*10+b%10)
    a.append(b*10+b%10+1)
print(b)
    


Fixed code:
from collections import deque
k = int(input())
a = deque([1,2,3,4,5,6,7,8,9])
count=0
while count !=k:
  b = a.popleft()
  count += 1
  if b%10==0:
    a.append(b*10)
    a.append(b*10+1)
  elif b%10==9:
    a.append(b*10+8)
    a.append(b*10+9)
  else:
    a.append(b*10+b%10-1)
    a.append(b*10+b%10)
    a.append(b*10+b%10+1)
print(b)
Buggy code:
#!/usr/bin/env python3

from collections import deque

k = int(input())

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

for _ in range(k):
    # print(f"loop: {_}")
    # print(f"que: {que}")
    x = que.pop()
    # print(f"x: {x}\n")
    if x % 10 != 0:
        que.appendleft(10 * x - 1)
    que.appendleft(10 * x)
    if x % 10 != 9:
        que.appendleft(10 * x + 1)
    if _ == k - 1:
        print(x)


Fixed code:
#!/usr/bin/env python3

from collections import deque

k = int(input())

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

x = -1
for _ in range(k):
    # print(f"loop: {_}")
    # print(f"que: {que}")
    x = que.pop()
    # print(f"x: {x}\n")
    if x % 10 != 0:
        que.appendleft(x * 10 + x % 10 - 1)
    que.appendleft(x * 10 + x % 10)
    if x % 10 != 9:
        que.appendleft(x * 10 + x % 10 + 1)

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

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

Fixed code:
import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(num):
  ans=q.get()
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
  q.put(10*ans+(ans%10))
  if ans%10!=9:
    q.put(10*ans+(ans%10)+1)
print(ans)
Buggy code:
from collections import deque

K=int(input())

todo=deque(list(map(str,range(1,10))))

count=0

while todo:
    num=todo.popleft()
    count+=1

    if count==k:
        print(num)
        exit()
    
    base=int(num[-1])
    n1=base-1
    if n1!=-1:
        todo.append(num+str(n1))
    
    n2=base
    todo.append(num+str(n2))

    n3=base+1

    if n3!=10:
        todo.append(num+str(n3))

Fixed code:
from collections import deque

K=int(input())

todo=deque(list(map(str,range(1,10))))

count=0

while todo:
    num=todo.popleft()
    count+=1

    if count==K:
        print(num)
        exit()
    
    base=int(num[-1])
    n1=base-1
    if n1!=-1:
        todo.append(num+str(n1))
    
    n2=base
    todo.append(num+str(n2))

    n3=base+1

    if n3!=10:
        todo.append(num+str(n3))
Buggy code:
#!/usr/bin/env python3
from heapq import *

a = [*range(1, 10)]
heapify(a)
i = 0
k = int(input())
c = 0
while True:
    t = str(heappop(a))
    i += 1
    if i == k:
        break
    if t[-1] != "0":
        heappush(a, int(t + str(int(t[-1]) - 1)))
    heappush(a, int(t + t[-1]))
    if t[0] != "9":
        heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)


Fixed code:
#!/usr/bin/env python3
from heapq import *

a = [*range(1, 10)]
heapify(a)
i = 0
k = int(input())
c = 0
while True:
    t = str(heappop(a))
    i += 1
    if i == k:
        break
    if t[-1] != "0":
        heappush(a, int(t + str(int(t[-1]) - 1)))
    heappush(a, int(t + t[-1]))
    if t[-1] != "9":
        heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)
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):
    runrun = q.popleft()
    rem = runrun % 10
    if rem == 0:
        q.append(runrun * 10)
        q.append(runrun * 10 + rem + 1)
    elif rem == 9:
        q.append(runrun * 10 + rem - 1)
        q.append(runrun * 10)
    else:
        q.append(runrun * 10 + rem - 1)
        q.append(runrun * 10)
        q.append(runrun * 10 + rem + 1)

print(runrun)


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):
    runrun = q.popleft()
    rem = runrun % 10
    if rem == 0:
        q.append(runrun * 10)
        q.append(runrun * 10 + rem + 1)
    elif rem == 9:
        q.append(runrun * 10 + rem - 1)
        q.append(runrun * 10 + rem)
    else:
        q.append(runrun * 10 + rem - 1)
        q.append(runrun * 10 + rem)
        q.append(runrun * 10 + rem + 1)

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


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

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

from collections import deque
num=deque()
for i in range(1,10):
  num.append(i)

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

print(l)
  
  

Fixed code:
K=int(input())

from collections import deque
num=deque()
for i in range(1,10):
  num.append(i)

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

print(l)
Buggy code:
import collections
k = int(input())
li = [str(i) for i in range(1,10)]
st_li = li[:]

q = collections.deque(li)
count = 0
n = 10 ** 10

for i in range(1,n):
    # print(st_li)
    a = q.popleft()
    num = int(a[-1])
    # print(num)
    if num != 0:
        aa = a + str(num-1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    aa = a + str(num)
    st_li.append(aa)
    count += 1
    if num != 9:
        aa = a + str(num+1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    if count > k:
        print(st_li[k-1])
        exit(0)


Fixed code:
import collections
k = int(input())
li = [str(i) for i in range(1,10)]
st_li = li[:]

q = collections.deque(li)
count = 0
n = 10 ** 10

for i in range(1,n):
    # print(st_li)
    a = q.popleft()
    num = int(a[-1])
    # print(num)
    if num != 0:
        aa = a + str(num-1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    aa = a + str(num)
    st_li.append(aa)
    q.append(aa)
    count += 1
    if num != 9:
        aa = a + str(num+1)
        st_li.append(aa)
        q.append(aa)
        count += 1
    if count > k:
        print(st_li[k-1])
        exit(0)
Buggy code:
from collections import deque
K = int(input())

d = deque()

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

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

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

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

for _ in range(K-1):
  q = Q.popleft()
  if q%10 != 0:
    Q.append(q*10+q%10-1)
  Q.append(q*10+q%10)
  if q%9 != 0:
    Q.append(q*10+q%10+1)
print(Q.popleft())

Fixed code:
from collections import deque
K = int(input())
Q = deque([i for i in range(1,10)])

for _ in range(K-1):
    q = Q.popleft()
    if q%10 != 0:
        Q.append(10*q+(q%10)-1)
    Q.append(10*q+(q%10))
    if q%10 != 9:
        Q.append(10*q+(q%10)+1)
print(Q.popleft())
Buggy code:
a=[]

def dfs(x):
  if x>3234566667:
    return
  a.append(x)
  for i in range(10):
    if abs(x%10-i) <= 1:
      dfs(x%10+i)
      
for i in range(1,10):
  dfs(i)
a =sorted(a)
k=int(input())
print(a[k-1])

Fixed code:
a = []

def dfs(x):
    if x > 3234566667:
        return
    a.append(x)
    for i in range(10):
        if abs(x%10-i) <= 1:
            dfs(x*10+i)

for i in range(1, 10):
    dfs(i)
a = sorted(a)
k = int(input())
print(a[k-1])
Buggy code:
from collections import deque
K = int(input())
que = deque()
que.extend([i for i in range(1,10)])

for k in range(K-2):
    out = que.popleft()
    div = out%10
    if div==0:
        que.extend([out*10,out*10+1])
    elif out%10==9:
        que.extend([out*10+8,out*10+9])
    else:
        que.extend([out*10-1+div,out*10+div,out*10+1+div])
print(que.popleft())

Fixed code:
from collections import deque
K = int(input())
que = deque()
que.extend([i for i in range(1,10)])

for k in range(K-1):
    out = que.popleft()
    div = out%10
    if div==0:
        que.extend([out*10,out*10+1])
    elif out%10==9:
        que.extend([out*10+8,out*10+9])
    else:
        que.extend([out*10-1+div,out*10+div,out*10+1+div])
print(que.popleft())
Buggy code:
from collections import deque
k=int(input())
q=deque(list(range(1, 10)))
ans,x,y,tmp=0,0,0,0
for i in range(k):
  ans=q.popleft()
  x,y=ans*10,ans%10
  tmp=10*x+y
  if y != 0:
    q.append(tmp-1)
  q.append(tmp)
  if y != 9:
    q.append(tmp+1)
print(ans)


Fixed code:
from collections import deque
k=int(input())
q=deque(list(range(1, 10)))
ans,x,y=0,0,0
for i in range(k):
  ans=q.popleft()
  y=ans%10
  x=ans*10+y
  if y != 0:
    q.append(x-1)
  q.append(x)
  if y != 9:
    q.append(x+1)
print(ans)
Buggy code:
def dp(i, j, memo):
    key = "{}.{}".format(i, j)

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

    if key in memo:
        return memo[key]

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

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

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


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

num = 0

i = 1
j = 0

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

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

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


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

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

    if key in memo:
        return memo[key]

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

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

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


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

num = 0

i = 1
j = 0

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

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

print("".join(map(str, ans)))
Buggy code:
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
B=[]
C=[]
D=[]
E=[]
F=[]
G=[]
H=[]
I=[]

def henkan(A):
    a=len(A)
    B=[]
    for i in range(a):
        if A[i]==0:
            B.append(10*A[i])
            B.append(10*A[i]+1)
        elif A[i]==9:
            B.append(10*A[i]+9)
            B.append(10*A[i]+8)
        else:
            x=A[i]%10
            B.append(10*A[i]+x)
            B.append(10*A[i]+x+1)
            B.append(10*A[i]+x-1)
    return B

B=henkan(A)
C=henkan(B)
D=henkan(C)
E=henkan(D)
F=henkan(E)
G=henkan(F)
H=henkan(G)
I=henkan(H)
ans=A+B+C+D+E+F+G+H+I
ans=sorted(ans)

print(ans[K-1])


Fixed code:
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
B=[]
C=[]
D=[]
E=[]
F=[]
G=[]
H=[]
I=[]
J=[]
def henkan(A):
    a=len(A)
    B=[]
    for i in range(a):
        if A[i]%10==0:
            B.append(10*A[i])
            B.append(10*A[i]+1)
        elif A[i]%10==9:
            B.append(10*A[i]+9)
            B.append(10*A[i]+8)
        else:
            x=A[i]%10
            B.append(10*A[i]+x)
            B.append(10*A[i]+x+1)
            B.append(10*A[i]+x-1)
    return B

B=henkan(A)
C=henkan(B)
D=henkan(C)
E=henkan(D)
F=henkan(E)
G=henkan(F)
H=henkan(G)
I=henkan(H)
J=henkan(I)
ans=A+B+C+D+E+F+G+H+I+J
ans=sorted(ans)

print(ans[K-1])
Buggy code:
# coding: utf-8
DATA = """
100000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()



def Calc():
	K = [int(i) for i in get_line().strip().split(" ")][0]
	ret = [str(_) for _ in range(1,10)]
	size = len(ret)
	start = 0
	print (ret)
	count = len(ret)
	while(size < K):
		for i in range(start, size):
			v = int(ret[i][-1])
			ll = ret[i]
			if not v == 0:
				count += 1
				ret.append(ll + str(v - 1))
			ret.append(ll + str(v))
			count += 1
			if not v == 9:
				count += 1
				ret.append(ll + str(v+1))

			if count >= K:
				break
		if count >= K:
			break
		start = size
		size = len(ret)
	print (ret[K-1])
Calc()

Fixed code:
# coding: utf-8
DATA = """
100000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

def Calc():
	K = [int(i) for i in get_line().strip().split(" ")][0]
	ret = [str(_) for _ in range(1,10)]
	size = len(ret)
	start = 0
	count = len(ret)
	while(size < K):
		for i in range(start, size):
			v = int(ret[i][-1])
			ll = ret[i]
			if not v == 0:
				count += 1
				ret.append(ll + str(v - 1))
			ret.append(ll + str(v))
			count += 1
			if not v == 9:
				count += 1
				ret.append(ll + str(v+1))

			if count >= K:
				break
		if count >= K:
			break
		start = size
		size = len(ret)
	print (ret[K-1])
Calc()