qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#!/usr/bin/env python3
# coding: utf-8
"""
about module
"""

def main():
    n, k = map(int, input().split())

    while n*2 > k:
        n = abs(n-k)
    return n

if __name__ == '__main__':
    print(main())


Fixed code:
#!/usr/bin/env python3
# coding: utf-8
"""
about module
"""


def main():
    n, k = map(int, input().split())
    if n > k:
        n = n % k

    while n * 2 > k:
        n = abs(n - k)
    return n


if __name__ == '__main__':
    print(main())
Buggy code:
n, k = map(int,input().split())
while n > k/2:
    n = abs(n - k)
print(n)

Fixed code:
n, k = map(int,input().split())
a = n // k
n = n - a*k
while n > k/2:
    n = abs(n - k)
print(n)
Buggy code:
##161 C
N,M= map(int, input().split())
amari= N % M
if(amari<=(N/2)):
    print(amari)
else:
   amari = amari-M
   print(amari)


Fixed code:
##161 C
N,M= map(int, input().split())
amari= N % M
if(amari<=(M/2)):
    print(amari)
else:
   amari = abs(amari-M)
   print(amari)
Buggy code:
N,K = map(int,input().split())
if N >= K:
    if N%K == 0:
        print(0)
        exit()
    else:
        print(0)
        exit()
else:
    A = [N]
    M = N 
    N = abs(N-K)
    A.append(N)
    while N != M:
        N = abs(N-K)
        A.append(N)
    print(min(A))

Fixed code:
N,K = map(int,input().split())

if N >= K:
    print(min(N % K,abs(N % K - K)))
else :
    A = [N]
    M = N 
    N = abs(N-K)
    A.append(N)
    while N != M:
        N = abs(N-K)
        A.append(N)
    print(min(A))
Buggy code:
num = list(map(int, input().split()))
min([num[0],num[0]%num[1],abs((num[0]//num[1])-num[1])])

Fixed code:
num = list(map(int, input().split()))
print(min([num[0],num[0]%num[1],abs((num[0]%num[1])-num[1])]))
Buggy code:
n,k=(map(int,input().split()))

ans=0

if n<k:
  print(ans)
else:
  ans=min(int(n%k),abs(int(n%k)-k))
  print(ans)

Fixed code:
n,k=(map(int,input().split()))

ans=0

if n<k:
  ans=min(n,abs(n-k))
  print(ans)
else:
  ans=min(int(n%k),abs(int(n%k)-k))
  print(ans)
Buggy code:
n, k = map(int, input().split())

x = n % k
print(min(x, abs(k-x))

Fixed code:
n, k = map(int, input().split())

x = n % k
print(min(x, abs(k-x)))
Buggy code:
n,k =map(int, input().split())
m = n % k
print(min(n, k - m))

Fixed code:
n,k =map(int, input().split())
m = n % k
print(min(m, k - m))
Buggy code:
import sys
input = sys.stdin.readline

N ,K = map(int,input().split())

intlist = [ (N % K) ,abs (( N % K ) - N )] 
print ( min(intlist) )

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

N ,K = map(int,input().split())

intlist = [ (N % K) ,abs (( N % K ) - K )] 
print (min(intlist))
Buggy code:
N, K = map(int, input().split(' '))


def main(n, k):
    print(n, k)
    if n % k == 0:
        # print('n%k=0')
        res = 0
    else:
        # print(n % k, abs((n % k)-k), n)
        res = min(n % k, abs((n % k) - k), n)

    print(res)


main(N, K)
# main(7, 4)
# main(2, 6)
# main(1000000000000000000, 1)
# main(9, 6)


Fixed code:
N, K = map(int, input().split(' '))


def main(n, k):
    # print(n, k)
    if n % k == 0:
        # print('n%k=0')
        res = 0
    else:
        # print(n % k, abs((n % k)-k), n)
        res = min(n % k, abs((n % k) - k), n)

    print(res)


main(N, K)
# main(7, 4)
# main(2, 6)
# main(1000000000000000000, 1)
# main(9, 6)
Buggy code:
#Input
n, k = map(int, input().split())

#Process
mod = n % k
if(mod > abs(mod - k)):
    Ans = aqbs(mod - k)
else:
    Ans = mod

#Output
print(Ans)

Fixed code:
#Input
n, k = map(int, input().split())

#Process
mod = n % k
if(mod > abs(mod - k)):
    Ans = abs(mod - k)
else:
    Ans = mod

#Output
print(Ans)
Buggy code:
N, K = map(int, input().split())

print(min(N%K, abs(N%K - K))

Fixed code:
N, K = map(int, input().split())
N = N%K
print(min(N, K - N))
Buggy code:
n, k = map(int, input().split())
L = []
if n > k:
  n = n - k*(n//k)
 
if n*2 <= k:
  print(n)
else:
  print(k)

Fixed code:
n, k = map(int, input().split())
L = []
if n > k:
  n = n - k*(n//k)
 
if n*2 <= k:
  print(n)
else:
  print(k-n)
Buggy code:
N,K=map(int,input().split())
n_b=N
a=N%k
if(K/2<a):
    print(a-k)
else:
    print(a)


Fixed code:
N,K=map(int,input().split())
n_b=N
a=N%K
if(K/2<a):
    print(abs(a-K))
else:
    print(a)
Buggy code:
[n, k] = map(int, input().split())
 
n -= n//k
if n > k//2:
  n = k -n
print(n)
  
  
  


Fixed code:
[n, k] = map(int, input().split())
 
n -= (n//k) * k
if n > k//2:
  n = k -n
print(n)
Buggy code:
#!/usr/bin/env python3

n, k = map(int, input().split())

#while n > abs(n-k):
#    n = abs(n-k)
while 2*n > k:
    
    if n > k:
        n = n-k
    elif n <= k:
        n = k-n
        
print(n)

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

n, k = map(int, input().split())

#while n > abs(n-k):
#    n = abs(n-k)
while 2*n > k:
    
    if n > k:
        n = n%k
    elif n <= k:
        n = k-n

print(n)
Buggy code:
n,k=map(int,input().split())
if k==1:
    print(0)
if n >= k:
    n = n % k

if abs(n-k)<n:
    n = abs(n-k)
    print(n)
else:
    print(n)


Fixed code:
n,k=map(int,input().split())

if n >= k:
    n = n % k
    
if abs(n-k)<n:
    n = abs(n-k)
    print(n)
else:
    print(n)
Buggy code:
N,K = map(int, input().split())
ans = 0


if (N < K):
    ans = N
#elif(N % K == 0):
 #   ans = 0
else:
    if (N % K == 0):
        ans = 0
    else:
    N = N % K
    if(N <= abs(N-K)):
        ans = N
    else:
        ans = abs(N-K)

print(ans)

Fixed code:
N,K = map(int, input().split())
ans = 0


#if (N < K):
 #   ans = N
if(N % K == 0):
    ans = 0
else:
    if (N < K):
        ans = N
    N = N % K
    if(N <= abs(N-K)):
        ans = N
    else:
        ans = abs(N-K)

print(ans)
Buggy code:
N,K = map(int, input().split())

a = N % K
if a == 0:
    print(0)
else:
    print(min(a, abs(a-k)))

Fixed code:
N,K = map(int, input().split())

a = N % K
if a == 0:
    print(0)
else:
    print(min(a, abs(a-K)))
Buggy code:
n,k = map(int,input().split())
 
if k==1 :
  ln=0
elif k==0 :
  ln=n
elif n>=k:
  a = n%k
  while 1:
    ln = a
    n = abs(n-k)
    if ln<=n:
      break
else:
  while 1:
    ln = n
    n = abs(n-k)
    if ln<=n:
      break
print(ln)

Fixed code:
n,k = map(int,input().split())
 
if k==1 :
  ln=0
elif k==0 :
  ln=n
elif n>=k:
  a = n%k
  n=a
  while 1:
    ln = n
    n = abs(a-k)
    if ln<=n:
      break
else:
  while 1:
    ln = n
    n = abs(n-k)
    if ln<=n:
      break
print(ln)
Buggy code:
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
mod = N % K
print(mod, abs(K - mod))

Fixed code:
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
mod = N % K
print(min(mod, abs(K - mod)))
Buggy code:
N, K = map(int, input().split())
ans = min(N % K, N - N % K)

Fixed code:
N, K = map(int, input().split())
ans = min(N % K, K - N % K)
print(ans)
Buggy code:
inp=[int(x) for x in input().split()]
n,k=inp[0],inp[1]
if n>k:
  print(n%k,k-n%k)
elif n<k:
  print(min(n,k-n))
else:
  print(0)

Fixed code:
inp=[int(x) for x in input().split()]
n,k=inp[0],inp[1]
if n>k:
  print(min(n%k,k-n%k))
elif n<k:
  print(min(n,k-n))
else:
  print(0)
Buggy code:
data = input().split()
n = int(data[0])
k = int(data[1])

if n > k :
  res = k - n % k
else:
  res = min(abs(n - k), n)

print(res)


Fixed code:
data = input().split()
n = int(data[0])
k = int(data[1])
 
if n > k :
  res = min(k - n % k, n % k)
else:
  res = min(abs(n - k), n, k - n % k)

print(res)
Buggy code:
N, K = input().split()
N = int(N)
K = int(K)

middle = N % K
answer = 0
if middle < N:
  answer = middle
while True:
  if abs(answer - K) < answer:
    answer = abs(answer-K)
  else:
    break
    
print(str(answer))

Fixed code:
N, K = input().split()
N = int(N)
K = int(K)

middle = N % K
answer = middle
while True:
  if abs(answer-K) > N:
    answer = N
    break
  if abs(answer - K) < answer:
    answer = abs(answer-K)
  else:
    break
    
print(str(answer))
Buggy code:
N,K = map(int, input().split())

if N<K:
  print(K-N)
else:
  print(min(N%K,abs(N%K-K)))

Fixed code:
N, K = map(int, input().split())

if(N <= K):
    print(min(N, K-N))
else:
    print(min(N%K, K-N%K))
Buggy code:
N,K=map(int,input().split())
if K==1:
  print("0")
if N > K :
  N-=(N//K)*K
if abs(K-N) < N:
  print(abs(K-N))
else:
  print(N)

Fixed code:
N,K=map(int,input().split())
if K==1:
  if N==0:
    print("1")
    exit()
  else:
    print("0")
    exit()
if N > K :
  N-=(N//K)*K
if abs(K-N) < N:
  print(abs(K-N))
else:
  print(N)
Buggy code:
n,k = map(int,input().split())
print(min(abs(n%k),k-abs(n%k))

Fixed code:
n, k = map(int, input().split())
print(min(n%k, -n%k))
Buggy code:
N, K = map(int, input().split())
x = N % K

print(min(x, abs(x - K))

Fixed code:
N, K = map(int, input().split())
x = N % K
print(min(x, abs(x - K)))
Buggy code:
N, K = map(int, open(0).read().split())
a = N % K
print(min(K - b, b))


Fixed code:
N, K = map(int, open(0).read().split())
a = N % K
print(min(K - a, a))
Buggy code:
l = input()
m = l.split(" ")
n = int(m[0])
k = int(m[1])
if n > k:
  n = n % k
  print(n)
if n < k:
  if n < (k-n):
    print(n)
  else:
    print(k-n)


Fixed code:
l = input()
m = l.split(" ")
n = int(m[0])
k = int(m[1])
if n > k:
  n = n % k
if n < (k-n):
    print(n)
else:
    print(k-n)
Buggy code:


N, K = map(int, input().split())

if N > K:
    N = N - K*(N//K)

if N=K:
    print(0)
else:
    print(K-N)

Fixed code:
N, K = map(int, input().split())

if N > K:
    N = N - K*(N//K)

if N==K:
    print(0)
else:
    print(min(N,K-N))
Buggy code:
n,k=map(int,input('').split(' '))
s=0
h=0

while s==0:
    h=n
    n=n-k
    if n<0:
        n=n*(-1)
    if h>n:
        s=0
    else:
        s=1
        n=h

print(n)

Fixed code:
n,k=map(int,input('').split(' '))
s=0
h=0

n=n%k
while s==0:
    h=n
    n=n-k
    if n<0:
        n=n*(-1)
    if h>n:
        s=0
    else:
        s=1
        n=h

print(n)
Buggy code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

#  = input()
#  = int(input())
N, K = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

if N >= K:
    seimin = N - (N//K) * K
    print(min(seimin, abs(seimin-K)))
else:
    print(min(N, N-K))


Fixed code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

#  = input()
#  = int(input())
N, K = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

if N >= K:
    seimin = N - (N//K) * K
    print(min(seimin, abs(seimin-K)))
else:
    print(min(N, abs(N-K)))
Buggy code:
N,K = map(int,input().split())

if N < K and abs(N-K) > N:
  print(N)
else:
  print(N % K)
  

Fixed code:
N,K = map(int,input().split())

if N < K and abs(N-K) > N:
  print(N)
else:
  n = N % K
  print(min(n,abs(n-K)))
Buggy code:
N, K = map(int, input().split())
while(1):
    tmpN = abs(N-K)
    if tmpN < N:
        N = tmpN
    else:
        break;
print(N)

Fixed code:
N, K = map(int, input().split())
N = N%K
while(1):
    tmpN = abs(N-K)
    if tmpN < N:
        N = tmpN
    else:
        break;
print(N)
Buggy code:
n,k=map(int,input().split())
if n<k:
  if:k<2*n:
      print(k-n)
  else:
    print(n)
elif n==k:
  print(0)
else:
  m=n//k
  r=n-m*k
  print(min(r,abs(r-k)))

Fixed code:
n,k=map(int,input().split())
if n<k:
  if k<2*n:
      print(k-n)
  else:
    print(n)
elif n==k:
  print(0)
else:
  m=n//k
  r=n-m*k
  print(min(r,abs(r-k)))
Buggy code:
n,k = map(int,input().split())

d = n//k

n = n - d*n

if abs(n-k)>n:
  print(n)
else:
  print(abs(n-k))
  


Fixed code:
n,k = map(int,input().split())

d = n//k

n = n - d*k

if abs(n-k)>n:
  print(n)
else:
  print(abs(n-k))
Buggy code:
n, k = map(int, input().split())
mov = n%k
ans = min(mov,abs(mov-k))

Fixed code:
n, k = map(int, input().split())
mov = n%k
ans = min(mov,abs(mov-k))
print(ans)
Buggy code:
N, K = map(int, input().split())

if abs(N-K) < N:
    if N >= K:
        print(N % K)
    else:
        print(K % N)
else:
    print(N)

Fixed code:
N,K = list(map(int,input().split()))
N = N % K
if N >= abs(N - K):
    print(abs(N-K))
else:
    print(N)
Buggy code:
N,K =int(input().split())
print(min(N%K, abs((N%K)-K)))

Fixed code:
N,K=map(int,input().split())
print(min(N%K,abs((N%K)-K)))
Buggy code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


n, k  = in_ints()
if n < k:
    n = k + abs(n)
print(n%k)

Fixed code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


n, k  = in_ints()
n = abs(n-k)
print(min(n%k, k- (n%k)))
Buggy code:
N,K=map(int,input().split())
M=N%K
print(min(M,N-M))

Fixed code:
N,K=map(int,input().split())
M=N%K
print(min(M,K-M))
Buggy code:
n,k = map(int, input().split())

while True:
    tmp = abs(n-k)

    if n > tmp:
        n = tmp
    else:
        break
print(n)


Fixed code:
n,k = map(int, input().split())

a = n%k
while True:
    tmp = abs(a-k)

    if a > tmp:
        a = tmp
    else:
        break
print(a)
Buggy code:
n, k = map(int, input().split())
m = n % k
print(m, abs(m-k))

Fixed code:
n, k = map(int, input().split())
m = n % k
print(min(m, abs(m-k)))
Buggy code:
n,k = map(int,input().split())
print(min(n%k,k-n%k)

Fixed code:
n,k = map(int,input().split())
ans = min( n%k, k-(n%k))
print(ans)
Buggy code:
n, k = map(int, input().split())

while abs(n-k) < n:
    n = abs(n-k)

print(n)

Fixed code:
n, k = map(int, input().split())

n = n % k

while abs(n-k) < n:
    n = abs(n-k)

print(n)
Buggy code:
n, k = map(int, input().split())
if n > n % k: n = n % k
if abs(n - k) > abs(k - n):
    print(abs (k - n))    
else:
    print(abs (n - k)) 


Fixed code:
n, k = map(int, input().split())
n = n % k
if abs(n - k) > abs(k - n):
    if n > abs(k - n):
        print(abs (k - n))
    else:
        print(n)  
else:
    if n > abs(n - k):
        print(abs (n - k))
    else:
        print(n)
Buggy code:
N,K=map(int,input().split())

if N==K:
  print(0)

elif N<K:
  lis1=[N,abs(N-K)]
  print(min(lis))
  
else:
  lis2=[N%K,abs(N%K-K)]
  print(min(lis2))
  

Fixed code:
N,K=map(int,input().split())

if N==K:
  print(0)

elif N<K:
  lis1=[N,abs(N-K)]
  print(min(lis1))
  
else:
  lis2=[N%K,abs(N%K-K)]
  print(min(lis2))
Buggy code:
N, K = map(int, input().split())

while(N > abs(N-K)):
  N = abs(N-K)
  
print(N)

Fixed code:
N, K = map(int, input().split())
N = N % K

while(N > abs(N-K)):
  N = abs(N-K)
  
print(N)
Buggy code:
N,K = map(int, input().split())
print(N%K,N%K-K,min(N%K,abs(N%K-K)))

Fixed code:
N,K = map(int, input().split())
print(min(N%K,abs(N%K-K)))
Buggy code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log
def main():
    k = int(input())
    k2 = int(log(ceil(k / 10), 3)) + 1
    def getlun(n, keta, first):
        if keta > k2:
            pass
        else:
            l1 = 10 ** (keta + 1) * first + n
            lunluns.append(l1)
            getlun(l1, keta + 1, first)
            if first > 1:
                l2 = 10 ** (keta + 1) * (first - 1) + n
                lunluns.append(l2)
                getlun(l2, keta + 1, first - 1)
            if first < 9:
                l3 = 10 ** (keta + 1) * (first + 1) + n
                lunluns.append(l3)
                getlun(l3, keta + 1, first + 1)
    lunluns = [i for i in range(1, 11)]
    for i1 in range(1, 10):
        getlun(i1, 0, i1)
    getlun(10, 1, 1)
    lunluns.sort()
    print(lunluns[k-1])

if __name__ == '__main__':
    main()

Fixed code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log
def main():
    k = int(input())
    k2 = int(log(ceil(k / 10), 3)) + 1
    def getlun(n, keta, last):
        lunluns.append(n)
        if keta > k2:
            pass
        else:
            l1 = n * 10 + last
            getlun(l1, keta + 1, last)
            if last > 0:
                l2 = n * 10 + last - 1
                getlun(l2, keta + 1, last - 1)
            if last < 9:
                l3 = n * 10 + last + 1
                getlun(l3, keta + 1, last + 1)
    lunluns = []
    for i1 in range(1, 10):
        getlun(i1, 0, i1)
    lunluns.sort()
    print(lunluns[k-1])

if __name__ == '__main__':
    main()
Buggy code:
k = int(input())

class Myqueue:
  def __init__(self):
    self.queue = []
    
  def enqueue (self, item):
    self.queue.append(item)
  
  def dequeue (self):
    if len(self.queue) ==0:
      return None
    result =self.queue[0]
    del self.queue[0]
    return result

myq = Myqueue()
myq.enqueue(1)
myq.enqueue(2)
myq.enqueue(3)
myq.enqueue(4)
myq.enqueue(5)
myq.enqueue(6)
myq.enqueue(7)
myq.enqueue(8)
myq.enqueue(9)

K = 9
s = 9
if k < 10:
  print(k)
elif k >= 10:
  while s <= k:
    x = myq.dequeue()
    I = x % 10
    if I == 0:
      myq.enqueue(x*10 + I)
      myq.enqueue(x*10 + (I+1))
      s += 2
    elif I ==9:
      myq.enqueue(x*10 + (I-1))
      myq.enqueue(x*10 + I)
      s += 2
    else:
      myq.enqueue(x*10 + (I-1))
      myq.enqueue(x*10 + I)
      myq.enqueue(x*10 + (I+1))
      s += 3

if s - 2 == k:
  print(myq.queue[-3])
elif s - 1 == k:
  print(myq.queue[-2])
elif s == k:
  print(myq.queue[-1])
else:
  print(myq.queue[-4])
  

Fixed code:
k = int(input())

class Myqueue:
  def __init__(self):
    self.queue = []
    
  def enqueue (self, item):
    self.queue.append(item)
  
  def dequeue (self):
    if len(self.queue) ==0:
      return None
    result =self.queue[0]
    del self.queue[0]
    return result

myq = Myqueue()
myq.enqueue(1)
myq.enqueue(2)
myq.enqueue(3)
myq.enqueue(4)
myq.enqueue(5)
myq.enqueue(6)
myq.enqueue(7)
myq.enqueue(8)
myq.enqueue(9)

K = 9
s = 9
if k < 10:
  None
elif k >= 10:
  while s <= k:
    x = myq.dequeue()
    I = x % 10
    if I == 0:
      myq.enqueue(x*10 + I)
      myq.enqueue(x*10 + (I+1))
      s += 2
    elif I ==9:
      myq.enqueue(x*10 + (I-1))
      myq.enqueue(x*10 + I)
      s += 2
    else:
      myq.enqueue(x*10 + (I-1))
      myq.enqueue(x*10 + I)
      myq.enqueue(x*10 + (I+1))
      s += 3

if k < 10:
  print(k)
elif s - 2 == k:
  print(myq.queue[-3])
elif s - 1 == k:
  print(myq.queue[-2])
elif s == k:
  print(myq.queue[-1])
elif s -3 == k:
  print(myq.queue[-4])
Buggy code:
n = int(input())
l = [_ for _ in range(1,10)]

cnt = 9
d = [-1, 0, 1]
for i in range(10**5):
    if cnt >= n: break
    for j in d:
        if 0 <= int(str(l[i])[-1]) + j <= 9:
            l.append(l[i]*10 + l[i][-1] + j)
            cnt += 1

print(l[n-1])


Fixed code:
n = int(input())
l = [_ for _ in range(1,10)]

cnt = 9
d = [-1, 0, 1]
for i in range(10**5):
    if cnt >= n: break
    for j in d:
        if 0 <= int(str(l[i])[-1]) + j <= 9:
            l.append(l[i]*10 + int(str(l[i])[-1]) + j)
            cnt += 1

print(l[n-1])
Buggy code:
#input
K = int(input())

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

for i in range(1, K+2):
    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)
    if i == K:
        print(x)

Fixed code:
import queue

#input
K = int(input())

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

for i in range(1, K+2):
    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)
    if i == K:
        print(x)
Buggy code:
import heapq
import sys

def solve(k):
    if k < 10:
        return k
    
    heap = [1,2,3,4,5,6,7,8,9]
    heapq.heapify(heap)

    for i in range(k-1):
        lunlun = heapq.heappop(heap)
        lastDigit = lunlun  % 10
        # print lunlun
        heapq.heappush(heap, (lunlun*10) + lastDigit)

        if lastDigit == 0:
            newlunlun = (lunlun * 10) + 1
            heapq.heappush(heap, newlunlun)    
        elif lastDigit == 9:
            newlunlun = (lunlun * 10) + 8
        else:
            newlunlun1 = (lunlun * 10) + lastDigit + 1
            newlunlun2 = (lunlun * 10) + lastDigit - 1
            heapq.heappush(heap, newlunlun1)
            heapq.heappush(heap, newlunlun2)

    return heapq.heappop(heap)

k = input()
print(solve(int(k)))

Fixed code:
import heapq
import sys

def solve(k):
    if k < 10:
        return k
    
    heap = [1,2,3,4,5,6,7,8,9]
    heapq.heapify(heap)

    for i in range(k-1):
        lunlun = heapq.heappop(heap)
        lastDigit = lunlun  % 10
        # print lunlun
        heapq.heappush(heap, (lunlun*10) + lastDigit)

        if lastDigit == 0:
            newlunlun = (lunlun * 10) + 1
            heapq.heappush(heap, newlunlun)    
        elif lastDigit == 9:
            newlunlun = (lunlun * 10) + 8
            heapq.heappush(heap, newlunlun)  
        else:
            newlunlun1 = (lunlun * 10) + lastDigit + 1
            newlunlun2 = (lunlun * 10) + lastDigit - 1
            heapq.heappush(heap, newlunlun1)
            heapq.heappush(heap, newlunlun2)

    return heapq.heappop(heap)

k = input()
# k = 100000
print(solve(int(k)))
Buggy code:
# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
queue = deque(queue)
L = []
cnt = 0
while cnt <= K:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v + v[-1])
        queue.append(v+str(t+1))
    cnt += 1
print(v)

Fixed code:
# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
queue = deque(queue)
L = []
cnt = 0
while cnt < K:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v + v[-1])
        queue.append(v+str(t+1))
    cnt += 1
print(v)
Buggy code:
n=int(input())
now=[1,2,3,4,5,6,7,8,9]
if n<10:
  print(now[n-1])
  exit()
cnt=9
while True:
  next=[]
  for s in now:
    s=str(s)
    if s[-1]!=0:
      cnt+=1
      if cnt<n:
        next.append(s+"0")
      else:
        print(s+"0")
        exit()
    cnt+=1
    if cnt<n:
      next.append(s+s[-1])
    else:
      print(s+s[-1])
      exit()
    if s[-1]!=9:
      cnt+=1
      if cnt<n:
        next.append(s+"9")
      else:
        print(s+"9")
        exit()
  now=next

Fixed code:
n=int(input())
now=[1,2,3,4,5,6,7,8,9]
if n<10:
  print(now[n-1])
  exit()
cnt=9
while True:
  next=[]
  for s in now:
    s=str(s)
    if s[-1]!="0":
      cnt+=1
      if cnt<n:
        next.append(s+str(int(s[-1])-1))
      else:
        print(s+str(int(s[-1])-1))
        exit()
    cnt+=1
    if cnt<n:
      next.append(s+s[-1])
    else:
      print(s+s[-1])
      exit()
    if s[-1]!="9":
      cnt+=1
      if cnt<n:
        next.append(s+str(int(s[-1])+1))
      else:
        print(s+str(int(s[-1])+1))
        exit()
  now=next
Buggy code:
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
I=0
while I<=K:
    if not A[I]%10==0:
        A.append(A[I]%10+10*A[I]-1)
    A.append(A[I]%10+10*A[I])
    if not A[I]%10==9:
        A.append(A[I]%10+10*A[I]+1)
    I+=1
    if len(A)>=K:
      break
print(A[I])

Fixed code:
K=int(input())
A=[1,2,3,4,5,6,7,8,9]
I=0
while I<=K:
    if not A[I]%10==0:
        A.append(A[I]%10+10*A[I]-1)
    A.append(A[I]%10+10*A[I])
    if not A[I]%10==9:
        A.append(A[I]%10+10*A[I]+1)
    if len(A)>=K:
      break
    I+=1
print(A[K-1])