qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, k = map(int, input().split())

mod = n % k

if mod > k - mod:
  print(mod)
else:
  print(k-mod)


Fixed code:
n, k = map(int, input().split())
 
mod = n % k
 
if mod > k - mod:
  print(k-mod)
else:
  print(mod)
Buggy code:
list_NK = list(map(int, input().split())) 
N = list_NK[0]
K = list_NK[1]
abs_now  = N
while all:
    abs_past = abs(abs_now - K)
    if(abs_past >= abs_now):
        break
    abs_now = abs_past
print(abs_past)



Fixed code:
list_NK = list(map(int, input().split())) 
N = list_NK[0]
K = list_NK[1]

number = N - K*(N//K)
abs_now  = number 
while all:
    abs_past = abs(abs_now - K)
    if(abs_past >= abs_now):
        break
    abs_now = abs_past
print(abs_now)
Buggy code:
import sys

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


if(N > K):
    if(N % K == 0):
        print(0)
        sys.exit()
    else:
        tmp=N % K
        print(min(tmp,abs(K - tmp)))
        sys.exit()
else:
    tmp = abs(N - K)
    if(tmp <= N):
        print(tmp)
    else:

Fixed code:
import sys

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


if(N > K):
    if(N % K == 0):
        print(0)
        sys.exit()
    else:
        tmp=N % K
        print(min(tmp,abs(K - tmp)))
        sys.exit()
else:
    tmp = abs(N - K)
    if(tmp <= N):
        print(tmp)
    else:
        print(N)
Buggy code:
N, K = map(int, input().split())

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

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

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

while True:
  if abs(x-k)>=min:
    break
  else:
    min=abs(x-k)
    x=abs(x-k)

print(min)

Fixed code:

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

while True:
  if abs(min-k)>=min:
    break
  else:
    min=abs(min-k)

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

if N%K != 0:
    print(min(N%K, N-N%K))
else:
    print(0)

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

if N%K != 0:
    print(min(N%K, K-N%K))
else:
    print(0)
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())
if n == k:
  print(0)
  exit()
if n > k:
  k, n = n, k
l = k%n
print(min(l, n-l))

Fixed code:
n, k = map(int, input().split())
if n == k:
  print(0)
  exit()
l = n%k
print(min(l, k-l))
Buggy code:
# C
import math
def my_round(val, digit=0):
    p = 10 ** digit
    return (val * p * 2 + 1) // 2 / p

n, k = map(int, input().split())
s = my_round(n / k)
print(min(n%k,k-s))

Fixed code:
# C
import math
def my_round(val, digit=0):
    p = 10 ** digit
    return (val * p * 2 + 1) // 2 / p

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

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

if n != k:
  x1 = n % k
  x2 = k - x1
  print(min(x1, x2))
else n == k:
  print(0)

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

if n != k:
  x1 = n % k
  x2 = k - x1
  print(min(x1, x2))
else:
  print(0)
Buggy code:
n, k = map(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:
N, K = map(int, input().split())
print(min(N%K, K(N%K)))


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

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

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

po=(N//K+1)*N-N
ne=N//K

print(min(po,ne))


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

po=(N//K+1)*K-N
ne=N%K

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

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

N = int(NK[0])
K = int(NK[1])

if N == K or K==1:
    print(0)

elif N > K:
    A = N % K
    if A > K:
        print(A-K)
    elif A == K:
        print(A)
    else:
        print(K-A)

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


Fixed code:
NK = input("").split()

N = int(NK[0])
K = int(NK[1])

if N == K or K==1:
    print(0)

elif N > K:
    A = N % K
    if A > K-A:
        print(K-A)

    else:
        print(A)

else:
    if N <= K-N:
        print(N)
    else:
        print(K-N)
Buggy code:
a = input()
a, b = a.split(' ')
a = int(a)
b = int(b)

a = a % b

print(a if a < b - a else b)



Fixed code:
a = input()
a, b = a.split(' ')
a = int(a)
b = int(b)

a = a % b

print(a if a < b - a else b - a)
Buggy code:
n,k=map(int,input().split(" "))

c=abs(n-k)
d=abs(c-k)
if(c+d==k):
    if(c>d):
        print(d)
    else:
        print(c)

if(k%n==0):
    if(n>k):
        print(0)
    else:
        print(n) 
    exit()

if(n>k):
    a=n-k*(n//k)
    b=k*(n//k+1)-n
    if(a>b):
        print(b)
    else:
        print(a)


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

c=abs(n-k)
d=abs(c-k)
if(c+d==k):
    if(c>d):
        print(d)
    else:
        print(c)
    exit()
if(n>=k):
    if(n%k==0):
        print(0)
        exit()
    else:
        a=n-k*(n//k)
        b=k*(n//k+1)-n
        if(a>b):
            print(b)
        else:
            print(a)
        exit()
else:
    
    while(1):
        a=abs(n-k)
        if(n>a):
            n=a
        else:
            print(n)
            exit()
Buggy code:
n, k = map(int, input().split())

mo = n%k

mok = abs(mo - k)

if mo = mok:
    print(mo)
else:
    print(mok)

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

mo = n%k

mok = abs(mo - k)

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

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


Fixed code:
n,k=map(int,input().split())
if k>=n:
  print(min(k-n,n))
else:
  m=n-(n//k)*k
  print(min(k-m,m))
Buggy code:
n, k = list(map(int, input().split(' ')))
result = 0
if k < n:
    result = n % k
elif n < k:
    result = n
print(result)

Fixed code:
n, k = list(map(int, input().split(' ')))
result = 0
if k < n:
    result = min(n%k, k-(n%k))
elif n < k:
    result = min(n, k-n)
print(result)
Buggy code:
n,k=map(int,input().split())
if n>=k:
    print(min(n%k,abs(k-n%k)))
else:
    print(n,abs(n-k))

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

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

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

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

if n<=(k/2):
    print(n)

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


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

if n<=(k/2):
    print(n)

else:
    n = n - (n//k)*k
    if n<= k/2:
        print(n)
    else:
        print(abs(n-k))
Buggy code:
import math
first_input = list(map(lambda x:int(x), input().split(" ")))
#second_input = list(map(lambda x:int(x), input().split(" ")))

N = first_input[0]
K = first_input[1]

#print(int(N/K))
if N>K:
    first_min_N = N - K*math.floor(N/K)

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


Fixed code:
import math
first_input = list(map(lambda x:int(x), input().split(" ")))
#second_input = list(map(lambda x:int(x), input().split(" ")))

N = first_input[0]
K = first_input[1]

#print(math.floor(N // K))
#print(K*math.floor(N // K))
if N>K:
    first_min_N = N - K*math.floor(N // K)
else:
    first_min_N = N

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

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

Fixed code:
N, K=map(int, input().split())
tmp=N%K
print(min(tmp, K-tmp))
Buggy code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = N % K
ans2 = (ans1 - K) * -1
print(ans1,ans2)
print(min(ans1,ans2))

Fixed code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = N % K
ans2 = (ans1 - K) * -1
# print(ans1,ans2)
print(min(ans1,ans2))
Buggy code:
a = list(map(int,input().split()))
print(a)
if a[0]<a[1]:
  print(str(min(a[0],a[1]-a[0])))
else:
  r=a[0]%a[1]
  print(str(min(r,a[1]-r)))

Fixed code:
a = list(map(int,input().split()))
if a[0]<a[1]:
  print(str(min(a[0],a[1]-a[0])))
else:
  r=a[0]%a[1]
  print(str(min(r,a[1]-r)))
Buggy code:
N, K = input().split();
N = int(N);
K = int(K);

amari = N % K;

hu = -1* (amari - K);

max_N = max(amari,hu);

print(max_N);


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

amari = N % K;

hu = -1* (amari - K);

max_N = min(amari,hu);

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

E = N % K

if (E == 0):
  print('0')
else:
  if (E > K):
    print(E)
  else:
    print(abs(E - K))

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

E = N % K

if (E == 0):
  print('0')
else:
  if E < abs(E - K):
    print(E)
  else:
    print(abs(E - K))
Buggy code:
N,K = map(int,input().split())
ans1 = N - K
ans2 = abs(ans1 - K)
print(min(ans1,ans2)

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

a = n // k

if n - k * a <= -(n - k * (a + 1)):
    print(n - k * a)

else:
    print(-n)


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

a = n // k

if n - k * a <= -(n - k * (a + 1)):
    print(n - k * a)

else:
    print(-(n - k * (a + 1)))
Buggy code:
import math

def nyu():
    N,K= map(int,(input().split()))
    return K,N


def check(K,N ):
    min = 0
    abs_num = 0

    OLD_ABS =N
    NEW_ABS = abs(K-N)

    while NEW_ABS < OLD_ABS:
        OLD_ABS = N #OK
        N = NEW_ABS ##OK
        NEW_ABS =abs(K-N)
    #    print("N_NEW",NEW_ABS,"OLS_ABS",OLD_ABS,"N",N)
    print(N)

    

     
            
K,N = nyu()
check(K,N)
#print(S)



Fixed code:
import math

def nyu():
    N,K= map(int,(input().split()))
    return K,N


def check(K,N ):
    min = 0
    abs_num = 0

    N = N%K

    OLD_ABS =N
    NEW_ABS = abs(K-N)

    while NEW_ABS < OLD_ABS:
        OLD_ABS = N #OK
        N = NEW_ABS ##OK
        NEW_ABS =abs(K-N)
    #    print("N_NEW",NEW_ABS,"OLS_ABS",OLD_ABS,"N",N)
    print(N)     
            
K,N = nyu()
check(K,N)
#print(S)
Buggy code:
import math

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

while True:
  if abs(tmp - K) < tmp:
    tmp = abs(tmp - K)
  else:
    break
 	
print(tmp)

Fixed code:
import math

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

while True:
  if abs(tmp - K) < tmp:
    tmp = abs(tmp - K)
  else:
    break
 	
print(tmp)
Buggy code:
n,k=map(int,input().split())

def abs(a):
    if a>=0:
        return a
    else:
        return -a

while True:
    b=n
    n=abs(n-k)
    if b<=n:
        print(b)
        break


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

def abs(a):
    if a>=0:
        return a
    else:
        return -a

m=n%k

while True:
    b=m
    m=abs(m-k)
    if b<=m:
        print(b)
        break
Buggy code:
n,k=map(int,input().split())
if n >= k:
    print(min(n%k,k-n%k))
elif n == 0:
    print(n)
else:
    print(min(n,n-k))

Fixed code:
n,k=map(int,input().split())
if n >= k:
    print(min(n%k,k-n%k))
elif n == 0:
    print(n)
else:
    print(min(n,k-n))
Buggy code:
import sys
input = sys.stdin.readline

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

ans = n%k

if ans < abs(ans-k):
    ans = abs(ans-k)

print(ans)

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

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

ans = n%k

if ans > abs(ans-k):
    ans = abs(ans-k)

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


Fixed code:
n,m=map(int,input().split())
ans=0
n%=m
#print(n,m)
ans=min(n,(m-n))
print(ans)
Buggy code:
N , K = map(int , input().split())

mini = N % K

if mini < abs(mini - K):
    mini = mini
else:
    mini = abs(mini - k)

print(mini)


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

mini = N % K

if mini < abs(mini - K):
    mini = mini
else:
    mini = abs(mini - K)

print(mini)
Buggy code:
n,k=map(int,input().split())
N=abs(n-k)
while N<n:
    n=N
    N=abs(n-k)
print(n)


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

Fixed code:
n, k = map(int, input().split())
x = n % k
print(min(x, k-x))
Buggy code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()

    ans = gcd(N, K) 
    print(0 if ans == 1 else ans)


if __name__ == '__main__':
    main()


Fixed code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()

    r = N%K
    if r == 0:
        print(0)
    else:
        if 2*r > K:
            print(abs(r - K))
        else:
            print(r)


if __name__ == '__main__':
    main()
Buggy code:
N, K = map(int,input().split())
q = N % K
ans = min(q, N-q)
print(ans)

Fixed code:
N, K = map(int,input().split())
q = N % K
ans = min(q, K-q)
print(ans)
Buggy code:
N, K = map(int, input().split())
print(min[N%K,K-N%K])

Fixed code:
N, K = map(int, input().split())
print(min([N%K,K-N%K]))
Buggy code:
# coding: utf-8
# Your code here!
import math
from decimal import *
getcontext().prec = 70

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

N = 10**18 - 9
K = 10
if N<= K:
    print(min(N,K-N))
else:

    N = N - math.floor(Decimal(N)/Decimal(K))*K 
    print(min(N, K-N)) 

Fixed code:
# coding: utf-8
# Your code here!
import math
from decimal import *
getcontext().prec = 70

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


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

    N = N - math.floor(Decimal(N)/Decimal(K))*K 
    print(min(N, K-N))
Buggy code:
n, k = map(int, input().split())

print(min(n % k), (k - (n % k)))


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


    
n1=n-(n//k)*k
n2=n-k
print(min(n1,n2))

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


    
n1=n-(n//k)*k
n2=abs(n1-k)
print(min(n1,n2))
Buggy code:
N, K = map(int, input().split())

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

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

m = -(-N//K)
print(min(N - m*K, -(N - (m+1)*K)))

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

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

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

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

m = N//K
print(min(N - m*K, -(N - (m+1)*K)))

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

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

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

m = -(-N//K)
print(abs(N - m*K))


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

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

print(min(N, abs(N-K)))
"""
"""
m = -(-N//K)
print(abs(N - m*K))
"""

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

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

if n >= k:
    print(n - k*(n // k))
else :
    print(n)

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

if n >= k:
    n -= k * (n // k)      

if k-n > n:
    print(n)
else:
    print(k-n)
Buggy code:
N,K =  map(int, input().split())
i=1
A[0]=N
if K!=1:
    while True:
        A[i]=abs(A[i]-K)
        if A[i] in A:
            break
        i+=1
    print(min(A))
else:
    print(0)

Fixed code:
N,K =  map(int, input().split())
i=1
X=N%K
A=[]
A.append(X)
if K!=1:
    while True:
        A.append(abs(A[i-1]-K))
        if A[i] in (A):
            break
        i+=1
    print(min(A))
else:
    print(0)
Buggy code:
N, K = map(int, input().split())

s = N % K

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

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

s = N % K

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

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

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

if N < K:
    print(N)
else:
    a = N % K
    b = abs(a-k)
    if a<b:
      print(a)
    else:
      print(b)
      


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

a = N % K
b = abs(a-K)
if a<b:
    print(a)
else:
    print(b)
Buggy code:
import math

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

ab = abs(n - k)

while n > ab:
  n = ab
  ab = abs(n - k)

print(n)

Fixed code:
import math

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

amari = n % k
n = amari

ab = abs(n - k)

while n > ab:
  n = ab
  ab = abs(n - k)

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

N_set = set([])
N_set.add(float('inf'))
N_new = N

while (N_new > 0 and N_new < min(N_set)):
    N_set.add(N_new)
    if N_new >= K:
        N_new = N_new % K
    else:
        N_new = K - N_new
    print("N_new", N_new)

N_set.add(N_new)

ans = min(N, min(N_set))

print(ans)

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

N_set = set([])
N_set.add(float('inf'))
N_new = N

while (N_new > 0 and N_new < min(N_set)):
    N_set.add(N_new)
    if N_new >= K:
        N_new = N_new % K
    else:
        N_new = K - N_new
 
N_set.add(N_new)

ans = min(N, min(N_set))

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

m=n%k
d=abs(m-k)

if m<k:
    print(m)
else:
    print(k)


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

m=n%k
d=abs(m-k)

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

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

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

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

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

Fixed code:
N,K = map(int,input().split())
if N > K:
    a = N % K
    ans = min(a,K-a)
    print(ans)
elif N < K:
    ans = min(N,K-N)
    print(ans)
elif N == K:
    print(0)
Buggy code:
def main():
  n,k = (int(x) for x in input().split())
  min = n

  while True:
    n = abs(n - k)
    if(n < min):
      min = n
    else:
      break

  print(min)

if __name__ == '__main__':
  main()


Fixed code:
def main():
  n,k = (int(x) for x in input().split())
  n = n % k
  min = n
  while True:
    n = abs(n - k)
    if(n < min):
      min = n
    else:
      break

  print(min)

if __name__ == '__main__':
  main()
Buggy code:
N,K=map(int,input().split())
while(1):
	A=N%K
	if N<K:
		print(min(N,abs(N-K)))
		exit()
	elif A==0:
		print(0)
		exit()
	else:
		print(A)
		exit()

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


if n>k:
    large=(n-(k*(n//k-1)))-k
    small=k-(n-k*(n//k))
    print(large,small)
    print(min(large,small))
elif n==k:
    print(0)
else:
    print(min(n,abs(n-k)))





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


if n>k:
    large=(n-(k*(n//k-1)))-k
    small=k-(n-k*(n//k))
    #print(large,small)
    print(min(large,small))
elif n==k:
    print(0)
else:
    print(min(n,abs(n-k)))
Buggy code:
list = input().split(" ")

startNum, standardNum = int(list[0]), int(list[1])

mod = startNum % standardNum
minusMod = abs(mod - standardNum)

result = mod if mod <= standardNum else minusMod

print(result)

Fixed code:
list = input().split(" ")

startNum, standardNum = int(list[0]), int(list[1])

mod = startNum % standardNum
minusMod = abs(mod - standardNum)

result = mod if mod <= minusMod else minusMod

print(result)
Buggy code:
#C
N, K = map(int,input().split())
if N%K==0:
    print(0)
else:
    print(min(N%K,-N%(K+1)))

Fixed code:
#C
N, K = map(int,input().split())
if N%K==0:
    print(0)
else:
    print(min(N%K,-(N%(K)-K)))
Buggy code:
n, k = map(int, input().split())
print(n%k, k - n%k)

Fixed code:
n, k = map(int, input().split())
print(min(n%k, k - n%k))
Buggy code:
X = input().split()
N = int(X[0])
K = int(X[1])

while N > K:
    N = abs(N - K)
N1 = abs(N - K)
if N > N1:
    print(N1)
else:
    print(N)

Fixed code:
X = input().split()
N = int(X[0])
K = int(X[1])

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

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

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

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

a = n % k
print(min(a, abs(a-k)))
Buggy code:
n, k = (int(x) for x in input().split())

while True:
  d = n - k
  if d < 0:
    d *= -1
  if d >= n:
    break
  else:
    n = d
print(n)

Fixed code:
n, k = (int(x) for x in input().split())

key = n % k


while True:
  d = key - k
  if d < 0:
    d *= -1
  if d >= key:
    break
  else:
    key = d
print(key)
Buggy code:
n, k = list(map(int, input().split()))

counter = 0
x_min = n
x = n
while not counter == 3:
    x = x % k
    if x_min > x:
        x_min = x
        counter = 1
    elif x_min == x:
        counter = counter + 1

print(x_min)


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

counter = 0
x_min = n
x = n
while not counter == 3:
    x = x % k
    if x_min > x:
        x_min = x
        counter = 1
    elif x_min == x:
        counter = counter + 1
    x = k - x

print(x_min)
Buggy code:
import sys
N, M = map(int, input().split())
ans = N
while True:
   if abs(ans-M) < ans:
        ans = abs(ans-M)
   else:
    print(ans)
    sys.exit()


Fixed code:
import sys
N, M = map(int, input().split())
ans = N%M
while True:
   if abs(ans-M) < ans:
        ans = abs(ans-M)
   else:
    print(ans)
    sys.exit()