qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import queue

S = int(input())

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

cnt = 9
num = 9
digit = 0

if S <= 9:
    print(S)
else:
    while cnt <= S:
        num = q.get()
        digit = int(str(num)[-1])
        num = num * 10

        if digit == 0:
            cnt += 1
            for i in range(2):
                if cnt == S:
                    print(num + i)
                else:
                    q.put(num+i)

        elif digit == 9:
            num += digit - 1
            for i in range(2):
                cnt += 1
                if cnt == S:
                    print(num + i)
                else:
                    q.put(num+i)
        else:
            num += digit - 1
            for i in range(3):
                cnt += 1
                if cnt == S:
                    print(num + i)
                else:
                    q.put(num+i)


Fixed code:
import queue

S = int(input())

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

cnt = 9
num = 9
digit = 0

if S <= 9:
    print(S)
else:
    while cnt <= S:
        num = q.get()
        digit = int(str(num)[-1])
        num = num * 10

        if digit == 0:
            for i in range(2):
                cnt += 1
                if cnt == S:
                    print(num + i)
                    exit()
                else:
                    q.put(num + i)

        elif digit == 9:
            num += digit - 1
            for i in range(2):
                cnt += 1
                if cnt == S:
                    print(num + i)
                    exit()
                else:
                    q.put(num+i)
        else:
            num += digit - 1
            for i in range(3):
                cnt += 1
                if cnt == S:
                    print(num + i)
                    exit()
                else:
                    q.put(num+i)
Buggy code:
N = int(input())
R=[["1","2","3","4","5","6","7","8","9"]]
count=9
for i in range(N):
  if count>=N:
    break
  else:
    temp=[]
    for r in R[i]:
      if r[-1]=="9":
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
      elif r[-1]=="0":
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
      else:
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
    R.append(temp)
    count+=len(temp)
N=N-(count-len(temp))
print(R[-1][N-1])

Fixed code:
N = int(input())
R=[["1","2","3","4","5","6","7","8","9"]]
count=9
temp=[]
for i in range(N):
  if count>=N:
    break
  else:
    temp=[]
    for r in R[i]:
      if r[-1]=="9":
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
      elif r[-1]=="0":
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
      else:
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
    R.append(temp)
    count+=len(temp)
N=N-(count-len(temp))
print(R[-1][N-1])
Buggy code:
import queue

k = int(input())

q = queue.Queue()

for i in range(1,10):
    q.put(i)
    
c = 1
while c<k:
    x = q.get()
    r = x%10
    if r != 0 and r != 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        q.put(10*x+r+1)
        c = c+1
    if r == 0:
        q.put(10*x)
        q.put(10*x+1)
        c = c+1
    if r == 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
    if c == k:
        print(x)
   

Fixed code:
import queue

k = int(input())

q = queue.Queue()

for i in range(1,10):
    q.put(i)
    
c = 0
while c<k:
    x = q.get()
    r = x%10
    if r != 0 and r != 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        q.put(10*x+r+1)
        c = c+1
    if r == 0:
        q.put(10*x)
        q.put(10*x+1)
        c = c+1
    if r == 9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        c = c+1
    if c == k:
        print(x)
Buggy code:
k = int(input())
lunlun = [0] * 100
lunlun[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 1

for i in range(9):
    n = len(lunlun[i])
    lunlun[i+1] = []
    for x in lunlun[i]:
        r = x%10
        if r > 0:
            lunlun[i+1].append(10*x + r-1)
        lunlun[i+1].append(10*x + r)
        if r < 9:
            lunlun[i+1].append(10*x + r+1)
    i += 1

for i in range(1, 11):
    for j in range(len(lunlun[i])):
        k -= 1
        if k == 0:
            print(lunlun[i][j])
            exit()


Fixed code:
k = int(input())
lunlun = [0] * 100
lunlun[1] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 1

for _ in range(9):
    n = len(lunlun[i])
    lunlun[i+1] = []
    for x in lunlun[i]:
        r = x%10
        if r > 0:
            lunlun[i+1].append(10*x + r-1)
        lunlun[i+1].append(10*x + r)
        if r < 9:
            lunlun[i+1].append(10*x + r+1)
    i += 1

for i in range(1, 11):
    for j in range(len(lunlun[i])):
        k -= 1
        if k == 0:
            print(lunlun[i][j])
            exit()
Buggy code:
k = int(input())

A = [i for i in range(1, 10)]

while k:
    if k <= len(A):
        print(A[k-1])
        exit()

    k -= len(A)
    
    old = []
    old, A = A, old
    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:
k = int(input())

A = [i for i in range(1, 10)]

while k:
    if k <= len(A):
        print(A[k-1])
        exit()

    k -= len(A)
    
    old = []
    old, A = A, old
    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:
def d1(x):
    y = x % 10
    if y == 0:
        return [0, 1]
    elif y == 9:
        return [8, 9]
    else:
        return [y-1, y, y+1]


K = int(input())

runrun = []
N = 0
digit = 0
while N < K:
    d_i = []
    if digit == 0:
        for i in range(1, 10):
            d_i.append(i)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1
    else:
        tmp = runrun[digit-1]
        for x in tmp:
            for y in d1(x):
                d_i.append(10*x+y)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1

print(runrun[-1][K-N+1])

Fixed code:
def d1(x):
    y = x % 10
    if y == 0:
        return [0, 1]
    elif y == 9:
        return [8, 9]
    else:
        return [y-1, y, y+1]


K = int(input())

runrun = []
N = 0
digit = 0
while N < K:
    d_i = []
    if digit == 0:
        for i in range(1, 10):
            d_i.append(i)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1
    else:
        tmp = runrun[digit-1]
        for x in tmp:
            for y in d1(x):
                d_i.append(10*x+y)
        N += len(d_i)
        runrun.append(d_i)
        digit += 1

print(runrun[-1][K-N-1])
Buggy code:
k = int(input())

from collection import deque
queue = deque(range(1,10))
count = 0
while count < k:
  count += 1
  tmp = queue.popleft()
  tail = tmp%10
  if tail != 0:
    queue.append(10*tmp+tail-1)
  queue.append(10*tmp)
  if tail != 9:
    queue.append(10*tmp+tail+1)

print(tmp)

Fixed code:
k = int(input())

from collections import deque
queue = deque(range(1,10))
count = 0

while count < k:
    tmp = queue.popleft()
    tail = tmp%10
    if tail != 0:
        queue.append(tmp*10+tail-1)
    queue.append(tmp*10+tail)
    if tail != 9:
        queue.append(tmp*10+tail+1)
    count += 1
    
print(tmp)
Buggy code:
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  print(lun,target,num)
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])


Fixed code:
K = int(input())
lun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
cnt = 0

while(len(lun) < K):
  target = lun[cnt]
  num = target % 10
  if num != 0:
      lun.append(target * 10 + num - 1)
  lun.append(target * 10 + num)
  if num != 9:
      lun.append(target * 10 + num + 1)
  cnt += 1

print(lun[K-1])
Buggy code:
k = int(input())

numset = {i for i in range(1,10)}
flag = False
count = len(numset)
if count >= k:
    flag = True
arr = [numset]
index = 0

while not flag:
    beforeset = arr[index]
    tmpset = set()
    for i in beforeset:
        tail = str(i)[-1]
        if tail == "0":
            tmpset.add(int(str(i)+str(0)))
            tmpset.add(int(str(i)+str(1)))
        elif tail == "9":
            tmpset.add(int(str(i)+str(8)))
            tmpset.add(int(str(i)+str(9)))
        else:
            tmpset.add(int(str(i)+str(int(tail))))
            tmpset.add(int(str(i)+str(int(tail)+1)))
            tmpset.add(int(str(i)+str(int(tail)-1)))
    count += len(tmpset)
    if count >= k:
        flag = True
    arr.append(tmpset)
    index += 1
    
totalarr = []
for tmpset in arr:
    totalarr += list(tmpset)
    
totalarr.sort()
print(totalarr[k])

Fixed code:
k = int(input())

numset = {i for i in range(1,10)}
flag = False
count = len(numset)
if count >= k:
    flag = True
arr = [numset]
index = 0

while not flag:
    beforeset = arr[index]
    tmpset = set()
    for i in beforeset:
        tail = str(i)[-1]
        if tail == "0":
            tmpset.add(int(str(i)+str(0)))
            tmpset.add(int(str(i)+str(1)))
        elif tail == "9":
            tmpset.add(int(str(i)+str(8)))
            tmpset.add(int(str(i)+str(9)))
        else:
            tmpset.add(int(str(i)+str(int(tail))))
            tmpset.add(int(str(i)+str(int(tail)+1)))
            tmpset.add(int(str(i)+str(int(tail)-1)))
    count += len(tmpset)
    if count >= k:
        flag = True
    arr.append(tmpset)
    index += 1
    
totalarr = []
for tmpset in arr:
    totalarr += list(tmpset)
    
totalarr.sort()
print(totalarr[k-1])
Buggy code:
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
print(x[k-1])  
  
  
  

Fixed code:
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])
Buggy code:
n=int(input())
from collections import deque
q=deque([])
i=0
while True:
  if i<=8:
    q.append(i+1)
    i+=1
    if i==k:break
    continue
  
  x=q.popleft()
  
  if x%10!=0:
    q.append(x*10+x%10-1)
    i+=1
    if i==k:break
    
  q.append(x*10+x%10)
  i+=1
  if i==k:break
  
  if x%10!=9:
    q.append(x*10+x%10+1)
    i+=1
    if i==k:break
      
print(q.pop())

Fixed code:
k=int(input())
from collections import deque
q=deque([])
i=0
while True:
  if i<=8:
    q.append(i+1)
    i+=1
    if i==k:break
    continue
  
  x=q.popleft()
  
  if x%10!=0:
    q.append(x*10+x%10-1)
    i+=1
    if i==k:break
    
  q.append(x*10+x%10)
  i+=1
  if i==k:break
  
  if x%10!=9:
    q.append(x*10+x%10+1)
    i+=1
    if i==k:break
      
print(q.pop())
Buggy code:
from collections import deque

K = int(input())

dq = deque(list(range(1,10)))

rep = 0

while rep < K:
    now = dq.popleft()
    rep += 1
    for i in (-1,0,1):
        if 0 <= now%10+1<10:
            dq.append(now*10+i)

print(now)

Fixed code:
from collections import deque

K = int(input())

dq = deque(list(range(1,10)))

for i in range(K):
    now = dq.popleft()
    for i in (-1,0,1):
        add = (now%10)+i
        if 0 <= add<10:
            dq.append(now*10+add)

print(now)
Buggy code:
from collections import deque

K = int(input())
Q = list(range(1, 10))

for i in range(K):
    x = Q[i]
    y = x%10
    if y != 0:
        Q.append(10*x + y-1)
    Q.append(10*x + y)
    if y != 9:
        Q.append(10*x + y+1)

print(Q[K])

Fixed code:
from collections import deque

K = int(input())
Q = list(range(1, 10))

for i in range(K):
    x = Q[i]
    y = x%10
    if y != 0:
        Q.append(10*x + y-1)
    Q.append(10*x + y)
    if y != 9:
        Q.append(10*x + y+1)

print(Q[K-1])
Buggy code:
K = int(input())
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,11):
    dfs(i)
a = sorted(a)
print(a[K-1])

Fixed code:
K = int(input())
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)
print(a[K-1])
Buggy code:
K = int(input())

def cal():
    count = 9
    d = [[1,2,3,4,5,6,7,8,9]]
    for i in range(10**9):
        d_ = []
        for j in range(len(d[i])):
            a = str(d[i][j])
            if a[-1]=="0":
                for k in [0,1]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return
            elif a[-1]=="9":
                for k in [8,9]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return 
            else:
                for k in [-1, 0, 1]:
                    d_.append(int(a)*10+int(a[-1])+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return
            d.append(d_)
if k <= 9:
    print(k)
else:
    cal()

Fixed code:
K = int(input())

def cal():
    count = 9
    d = [[1,2,3,4,5,6,7,8,9]]
    for i in range(10**9):
        d_ = []
        for j in range(len(d[i])):
            a = str(d[i][j])
            if a[-1]=="0":
                for k in [0, 1]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return
            elif a[-1]=="9":
                for k in [8, 9]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return 
            else:
                for k in [-1, 0, 1]:
                    d_.append(int(a)*10+int(a[-1])+k)
                    count += 1
                    if K == count:
                        print(d_[-1])
                        return
        d.append(d_)
if K <= 9:
    print(K)
else:
    cal()
Buggy code:
from collections import deque

K = int(input())

count = 0
ans = 0
Q = deque([1,2,3,4,5,6,7,8,9])
while count != K:
  a = Q.popleft()
  b = a%10
  if b != 0:
    Q.append(q*10 + b - 1)
  Q.append(q*10)
  if b != 9:
    Q.append(q*10 + b + 1)
  count += 1
  ans = q
print(q)

Fixed code:
from collections import deque
 
K = int(input())
 
count = 0
Q = deque([1,2,3,4,5,6,7,8,9])
while count != K:
  a = Q.popleft()
  b = a%10
  if b != 0:
    Q.append(a*10 + b - 1)
  Q.append(a*10 + b)
  if b != 9:
    Q.append(a*10 + b + 1)
  count += 1
  #print(Q)
print(a)
Buggy code:
def main():
    k = int(input())
    ary = [1,2,3,4,5,6,7,8,9]
    cnt = 9
    now = 0
    up_tmp = 0
    if k < 10:
        print(k)
        return
    while True:
        tmp = []
        for i in range(up_tmp,len(ary)):
            a_i = ary[i]
            keta_1 = int(list(str(a_i))[-1])
            if len(str(a_i * 10 + keta_1)) == len(str(a_i * 10 + keta_1 - 1)):
                cnt += 1
                now = a_i * 10 + keta_1 - 1
                tmp.append(now)

                if cnt == k:
                    print(now)
                    # print(ary)
                    # print(tmp)
                    return
            cnt += 1
            now = a_i * 10 + keta_1
            tmp.append(now)
            if cnt == k:
                print(now)
                # print(ary)
                # print(tmp)
                return
            if len(str(a_i * 10 + keta_1)) == len(str(a_i * 10 + keta_1 + 1)):
                cnt += 1
                now = a_i * 10 + keta_1 + 1
                tmp.append(now)

                if cnt == k:
                    print(now)
                    # print(ary)
                    # print(tmp)
                    return
        up_tmp = len(ary)
        ary.extend(tmp)



if __name__=='__main__':
    main()


Fixed code:
def main():
    k = int(input())
    ary = [1,2,3,4,5,6,7,8,9]
    cnt = 9
    now = 0
    up_tmp = 0
    if k < 10:
        print(k)
        return
    while True:
        tmp = []
        for i in range(up_tmp,len(ary)):
            a_i = ary[i]
            keta_1 = int(list(str(a_i))[-1])
            if keta_1 != 0:
                cnt += 1
                now = a_i * 10 + keta_1 - 1
                tmp.append(now)

                if cnt == k:
                    print(now)
                    # print(ary)
                    # print(tmp)
                    return
            cnt += 1
            now = a_i * 10 + keta_1
            tmp.append(now)
            if cnt == k:
                print(now)
                # print(ary)
                # print(tmp)
                return
            if keta_1 != 9:
                cnt += 1
                now = a_i * 10 + keta_1 + 1
                tmp.append(now)

                if cnt == k:
                    print(now)
                    # print(ary)
                    # print(tmp)
                    return
        up_tmp = len(ary)
        ary.extend(tmp)



if __name__=='__main__':
    main()
Buggy code:
# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())
# print(K)
N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 9
for i in range(len(A)):
    bts(A[i], 1, 100)
# print(cnt1)


Fixed code:
# from sys import stdin
import sys
global cnt1


def bts(A, cnt, max):
    # print(A)
    if cnt == max:
        global cnt1
        cnt1 = cnt1+1
        if cnt1 == K:
            print(A)
            sys.exit()
        return
    cnt = cnt+1
    if A % 10 == 0:
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)
    elif A % 10 == 9:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
    else:
        bts(A*10+(A % 10)-1, cnt, max)
        bts(A*10+(A % 10), cnt, max)
        bts(A*10+(A % 10)+1, cnt, max)


K = int(input())
# print(K)
N = 9
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# global cnt1
cnt1 = 0
for k in range(1, 11):
    for i in range(len(A)):
        bts(A[i], 1, k)
# print(cnt1)
Buggy code:
from collections import deque
K = int(input())
q = deque(str(i) for i in range(1, 10))
cnt = 9
if K < 10:
    print(K); return
while True:
    tmp = q.popleft()
    las = int(tmp[-1])
    for i in range(las-1, las+2):
        if 0<=i<=9:
            q.append(tmp + str(i))
            cnt += 1
            if cnt==K:
                print(q.pop()); return

Fixed code:
def resolve():
	from collections import deque
	K = int(input())
	q = deque(str(i) for i in range(1, 10))
	cnt = 9
	if K < 10:
		print(K); return
	while True:
		tmp = q.popleft()
		las = int(tmp[-1])
		for i in range(las-1, las+2):
			if 0<=i<=9:
				q.append(tmp + str(i))
				cnt += 1
				if cnt==K:
					print(q.pop()); return
resolve()
Buggy code:
k = int(input())
a = [x for x in range(1, 10)]

while(1):
    if(k <= len(a)):
        print(a[k-1])
        break
    k -= len(a)
    old = []
    old, a = a, old
    for x in old:
        for i in range(-1, 2):
            d = x % 10+1
            if(d < 0 or d > 9):
                continue
            nx = x*10 + d
            a.append(nx)


Fixed code:
k = int(input())
a = [x for x in range(1, 10)]

while(1):
    if(k <= len(a)):
        print(a[k-1])
        break
    k -= len(a)
    old = []
    old, a = a, old
    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:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

k = INT()
s = list('00000000000')

for i in range(k):
    for j in range(len(s)):
        if s[j] != '9' and ( s[j+1] == '0' or int(s[j]) < int(s[j+1]) + 1 ):
            s[j] = str(int(s[j]) + 1)
        else:
            continue

        while j > 0:
            j -= 1
            s[j] = str(max(0, int(s[j+1])-1))
        break

ans = int("".join(reversed(s)))
print(ans)

Fixed code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

k = INT()
s = list('00000000000')

for i in range(k):
    for j in range(len(s)):
        if s[j] != '9' and ( int("".join(s[j+1:])) == 0 or int(s[j]) < int(s[j+1]) + 1 ):
            s[j] = str(int(s[j]) + 1)
        else:
            continue

        while j > 0:
            j -= 1
            s[j] = str(max(0, int(s[j+1])-1))
        break

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

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

def add_v(v):
  global cands
  global K
  v0 = v % 10
  v0 = int(v[-1])
  if v0 == 0:
    cands += [v*10, v*10+1]
    K -=2
  elif v0 == 9:
    cands += [v*10+8, v*10+9]
    K -= 2
  else:
    cands += [v*10+v0-1, v*10+v0, v*10+v0+1]
    K -= 3

K = int(input())
idk = K
K -= 9
idx = 0
while K >= 0:
  add_v(cands[idx])
  idx += 1

print(cands[idk-1])

Fixed code:
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def add_v(v):
  global cands
  global K
  v0 = v % 10
  if v0 == 0:
    cands += [v*10, v*10+1]
    K -=2
  elif v0 == 9:
    cands += [v*10+8, v*10+9]
    K -= 2
  else:
    cands += [v*10+v0-1, v*10+v0, v*10+v0+1]
    K -= 3

K = int(input())
idk = K
K -= 9
idx = 0
while K >= 0:
  add_v(cands[idx])
  idx += 1

print(cands[idk-1])