qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,K=map(int,input().split())
A=0
for a in range(100000000000000):
    tugi=abs(N-K)
    N=tugi
    A=tugi
    tugi=abs(N-K)
    B=tugi
    N=tugi
    tugi=abs(N-K)
    if A==tugi:
        if B<A:
            print(B)
            break
        else:
       	    print(A)
            break

Fixed code:
N,K=map(int,input().split())
A=0
for a in range(100000000000000):
    if N>K:
        kot=N%K
        if abs(K-kot)>kot:
            print(kot)
            break
        else:
            print(abs(K-kot))
            break
    if N%K==0:
        print(0)
        break
    if N<K:
        if abs(N-K)<N:
            print(abs(N-K))
            break
        else:
            print(N)
            break
    tugi=abs(N-K)
    N=tugi
    A=tugi
    tugi=abs(N-K)
    B=tugi
    N=tugi
    tugi=abs(N-K)
    if A==tugi:
        if B<A:
            print(B)
            break
        else:
       	    print(A)
            break
Buggy code:
n,k = map(int,input().split())

ans1 = n%k
print(ans1)
if ans1 > k-ans1:
  ans1 = k-ans1
print(ans1)

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

ans1 = n%k

if ans1 > k-ans1:
  ans1 = k-ans1
print(ans1)
Buggy code:
#!/usr/bin/env python3

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

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

N, K = map(int, input().split())
if N <=K:
    print(min(abs(N-K), N))
else:
    print(min(N%K, K-N%K))
Buggy code:
n, k = (int(i) for i in input().split())
if k > n:
    print(n)
elif n % k == 0:
    print(0)
else:
    q = n % k
    p = (k * ((n//k) + 1)) - k
    print(min(p, q))

Fixed code:
n, k = (int(i) for i in input().split())
if k > n:
    print(min(n, abs(n-k)))
elif n % k == 0:
    print(0)
else:
    q = n % k
    p = (k * (n//k+1)) - n
    print(min(p, q))
Buggy code:
#coding:utf-8
N,K=map(int,input().split())

if (N%K) <=(K/2):
	x=N%K
else:
	x=N-N%K
	
print(x)

Fixed code:
#coding:utf-8
N,K=map(int,input().split())

if (N%K) <=(K/2):
	x=N%K
else:
	x=K-N%K
	
print(x)
Buggy code:
N, K = map(int,input().split())
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())
while N > K//2:
  N = abs(N-K)
print(N)

Fixed code:
N, K = map(int, input().split())
a = (N//K) * K
N -= a
while N > K//2:
  N = abs(N-K)
print(N)
Buggy code:
n,k=int(input().split())
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)

Fixed code:
n,k=input().split()
n=int(n)
k=int(k)
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)
Buggy code:
n,k=map(int,input().split())
n=int(n)
k=int(k)
n = n % k
minimam = k
record=[]
for i in range(k):
  if n < minimam:
    minimam = n
  n = abs(n-k)
  record.append(n)
  if n in record:
    break
print(minimam)

Fixed code:
n,k=map(int,input().split())
n=int(n)
k=int(k)
n = n % k
minimam = n
record=[]
for i in range(k):
  n=abs(n-k)
  if n < minimam:
    minimam = n
  record.append(n)
  if n in record:
    break
print(minimam)
Buggy code:
N,K=map(int,input().split())

N=N%K

print(min(K,abs(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())
res = 0

if N % K == 0:
    res = 0
elif N % K > 2 / K:
    res = K - (N % K)
else:
    res = N % K

print(res)


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

if N % K == 0:
    res = 0
elif N % K > K / 2:
    res = K - (N % K)
else:
    res = N % K

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

q = N // K
Na = N - q*K
Nb = abs(Na - K)

if Na >= Nb:
  	print(Na)
else:
  	print(Nb)

Fixed code:
N, K = map(int, input().split())
 
q = N // K
Na = N - q*K
Nb = abs(Na - K)
 
if Na >= Nb:
  	print(Nb)
else:
  	print(Na)
Buggy code:
n, k = map(int, input().split())
x = n%k
ans = min(x,n-x)
print(ans)

Fixed code:
n, k = map(int, input().split())
x = n%k
ans = min(x,k-x)
print(ans)
Buggy code:
def main():
  n, k = map(int, input().rstrip().split())
  
  if n % k <= k / 2:
	print(n % k)
  else:
    print(k - (n % k))


if __name__ == '__main__':
    main()


Fixed code:
def main():
  n, k = map(int, input().rstrip().split())
  
  if n % k <= k / 2:
    print(n % k)
  else:
    print(k - (n % k))


if __name__ == '__main__':
  main()
Buggy code:
if __name__ == "__main__":
	N, K = list(map(int, input().split()))
    r = N%K
    print(r) if r < abs(r-K) else print(abs(r-K))


Fixed code:
if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    r = N%K
    if r < abs(r-K):
        print(r)  
    else:
        print(abs(r-K))
Buggy code:
#/usr/bin/env python

import sys

N, K = [int(x) for x in sys.stdin.readline().strip().split()]

mod = N % K

if mod < (2 / K):
    print(mod)
else:
    print(K - mod)



Fixed code:
#/usr/bin/env python

import sys

N, K = [int(x) for x in sys.stdin.readline().strip().split()]

mod = N % K

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


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

if N == K:
    ans = 0
elif N > K:
    ans = N % K
else:
    ans = min(N, abs(N-K))

print(ans)

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

if N == K:
    ans = 0
elif N == 0:
    ans = 0
elif N > K:
    t = N % K
    ans = min(t, abs(t-K))
else:
    ans = min(N, abs(N-K))

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

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

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

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

Fixed code:
N,K = map(int,input().split())
if N%K == 0:
    print(0)
else:
    if abs(K - N%K) >= N%K:
        print(N%K)
    else:
        print(abs(K - N%K))
Buggy code:
N, K = map(int, input().split())
r = N%K
if r == 0 or r == 1:
  print(r)
s = abs(r - K)
if s < r:
  print(s)
else:
  print(r)

Fixed code:
N, K = map(int, input().split())
r = N%K
if r == 0 or r == 1:
  print(r)
else:
  s = abs(r - K)
  if s < r:
    print(s)
  else:
    print(r)
Buggy code:
n, k = [int(i) for i in input().split()]
result = n % abs(n - k)
print(result)


Fixed code:
n, k = [int(i) for i in input().split()]

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

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

temp=min(n,k)

for i in range(10^6):
    temp=min(temp,abs(temp-k))


print(temp)

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

temp=n

temp=min(n,n%k)

for i in range(10^6):
    temp=min(temp,abs(temp-k))

print(temp)
Buggy code:
x,y= list(map(int, input().split()))
if x%y==0:
    print(0)
else:
    print(min((x%y),(y-(x%y)))

Fixed code:
x,y= list(map(int, input().split()))
if x%y==0:
    print(0)
else:
    z=min((x%y),(y-(x%y)))
    print(z)
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 %= K

while abs(N - K) < N:
    N = abs(N - K)

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

Fixed code:
N,K = map(int,input().split())
r = N%K
s = K-r
print(min([r,s]))
Buggy code:
import math
if __name__ == "__main__":
    N, K = map(int, input().split())
    if N == 0:
        ret = 0
        print(int(ret))
        exit(0)
    ret =  N // K * K
    while ret > abs(ret-K):
        ret = abs(ret-K)
    print(int(ret))

Fixed code:
import math
if __name__ == "__main__":
    N, K = map(int, input().split())
    if N == 0:
        ret = 0
        print(int(ret))
        exit(0)
    ret = N - N // K * K
    while ret > abs(ret-K):
        ret = abs(ret-K)
    print(int(ret))
Buggy code:
N, K = map(int, input().split())
N = N % K

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

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

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

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

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

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

if N > K:
    x = N-K
else:
    x = K-N

while  N > x :
    N = x

    if N > K:
        x = N-K

    else:
        x = K-N

print(N)

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

if N > K:
    x = N%K
else:
    x = K-N

while  N > x :
    N = x

    if N > K:
        x = N-K

    else:
        x = K-N

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

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

Fixed code:
N, K = map(int, input().split())
r1 = N % K
print(min(r1, K - r1))
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:
#coding:utf-8
import math
n, k = map(int, input().split())

if n < k:
    print(min(n, k%n))
elif k == 1 or n == 0 or n%k == 0:
    print(0)
elif k % 2 == 0 and n % 2 == 0 and n%k != 0:
    print(n%k)
elif n%k != 0:
    print(min(abs(n%k-k), n%k))


Fixed code:
#coding:utf-8
import math
n, k = map(int, input().split())

if n < k:
    print(min(n, abs(n-k)))
elif k == 1 or n == 0 or n%k == 0:
    print(0)
elif n%k != 0:
    print(min(abs(n%k-k), n%k))
Buggy code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
if N == K:
    print(0)
elif N > K:
    N %= K
    print(min(N, abs(N - K)))
else:
    print(min(K, abs(N - K)))


Fixed code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
if N == K:
    print(0)
elif N > K:
    N %= K
    print(min(N, abs(N - K)))
else:
    print(min(N, abs(N - K)))
Buggy code:
import math
N, K = map(int, input().split())
while True:
    if abs(N-K) < N:
        N = abs(N-K)
    else:
        print(N)
        break

Fixed code:
import math
N, K = map(int, input().split())
N = N%K
while True:
    if abs(N-K) < N:
        N = abs(N-K)
    else:
        print(N)
        break
Buggy code:
N, K = map(int, input().split())
print(min([N, N%K, N-N%K]))

Fixed code:
N, K = map(int, input().split())
print(min([N, N%K, abs(K-N%K)]))
Buggy code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

ans = 0
if N > K:
    ans = N % K
else:
    ans = min(N, abs(N-K))

print(ans)


Fixed code:
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

ans = 0
if N > K:
    ans = min(N % K, abs(K - N % K))
else:
    ans = min(N, abs(N-K))

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

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

if N%K == 0:
    print(0)

elif N<K and N<=K-N:
    print(N)

elif N<K and N>K-N:
    print(K-N)

elif N>K:
    print(N%K)


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

if N%K == 0:
    print(0)

elif N<K and N<=K-N:
    print(N)

elif N<K and N>K-N:
    print(K-N)

elif N>K:
    if K-(N%K)>N%K:
        print(N%K)
    else:
        print(K-(N%K))
Buggy code:
#AtCoder
N, K = map(int, input().split())
q, mod = divmod(N, K)
print(min(q, mod))

Fixed code:
#AtCoder
N, K = map(int, input().split())
q, mod = divmod(N, K)
print(min(mod, K-mod))
Buggy code:
N , K = (int(x) for x in input().split())

remin = N%K
print(K-remin)
print(remin)
ans = min(remin,K-remin)

print(ans)
  

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

remin = N%K

ans = min(remin,K-remin)

print(ans)
Buggy code:
N, K = map(int, input().split())
store = N
x = N % K
if N == 0:
    print(0)
elif N == store:
    print(abs(N - K))
else:
    while x < store:
        store = x
        x = abs(x - K)

    print(store)


Fixed code:
N, K = map(int, input().split())
store = N
x = N % K
if N == 0:
    print(0)
else:
    while x < store:
        store = x
        x = abs(x - K)

    if store > abs(N - K):
        print(abs(N - K))
    else:
        print(store)
Buggy code:
nums = list(map(int, input().split()))
n = nums[0]
k = nums[1]

x  = n % k

print(min(n, k - n))


Fixed code:
nums = list(map(int, input().split()))
n = nums[0]
k = nums[1]

n  = n % k

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

z = a % b

if z > b/2:
    print(abs(z-k))
else:
    print(z)

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


z = a % b


if z > b/2:
    print(abs(z-b))
else:
    print(z)
Buggy code:
N, K = map(int, input().split())

a = abs(N-K)

b = abs(a-K)

while a >= b:
    a = b
    b = abs(b-K)

print(a)

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

a = N%K

b = abs(a-K)

while a > b:
    a = b
    b = abs(b-K)

print(a)
Buggy code:
N, K = map(int, input().split())
if N == K:
    print(0)
    exit()

tmp1 = 0
if N > K:
    tmp, m = divmod(N, K)
    if m == 0:
        tmp1 = N % (tmp + 1)
else:
    tmp = abs(N - K)
    tmp1 = min(N % K, tmp)

print(tmp1)

Fixed code:
N, K = map(int, input().split())
if N == K:
    print(0)
    exit()

tmp1 = 0
if N > K:
    tmp, m = divmod(N, K)
    tmp1 = m
    tmp1 = min(tmp1, abs(m - K))
else:
    tmp = abs(N - K)
    tmp1 = min(N % K, tmp)

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

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

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

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

if n <= k :
    print(min(n, k-n))
    exit(0)
if n>k:
    while n-k >=0:
        n -= k
    print(min(n, k-n))

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

if n <= k :
    print(min(n, k-n))
    exit(0)
if n>k:
    n = n%k
    print(min(n, k-n))
Buggy code:
n,k=map(int,input().split())
print(min(n%k,n-n%k))

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

c1 = n % k
c2 = -1 * (c1 - k)
return min([c1, c2])

Fixed code:
buf = input().split()
n = int(buf[0])
k = int(buf[1])

c1 = n % k
c2 = -1 * (c1 - k)

print(min([c1, c2]))
Buggy code:
n,k=map(int,input().split())
if not n or k == 1:
	print(0)
else:
	if n >= k:
		print(n%k)
	else:
		print(min(n,k-n))

Fixed code:
n,k=map(int,input().split())
if not n or k == 1:
	print(0)
else:
	if n >= k:
		n = n%k
	print(min(n,k-n))
Buggy code:
import sys
 
N,K = list(map(int,input().split()))	

ans=N%K

if ans==0:
  print(0)
elif ans>ans-K:
  print(ans-K)
else:
  print(ans)

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

ans=N%K

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

if N % K == 0:
  answer = 0
else:
  if N % K >= N:
    answer = N
  else:
    answer = N % K

  
print(answer)

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

if N % K == 0:
  answer = 0
else:
  if abs(N % K - K) >= N % K:
    answer = N % K
  else:
    answer = abs(N % K - K)

  
print(answer)
Buggy code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    n, k = map(int, input().split())
    if k == 1:
        print(0)
        sys.exit()
    r1 = k % n
    r2 = abs(r1 - k)
    r = min(r1, r2)
    print(r)


if __name__ == '__main__':
    main()

Fixed code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    n, k = map(int, input().split())
    if k == 1:
        print(0)
        sys.exit()
    r1 = n % k
    r2 = abs(r1 - k)
    r = min(r1, r2)
    print(r)


if __name__ == '__main__':
    main()
Buggy code:
list=list(map(int,input().split()))
x=list[0]
k=list[1]
if list[0]>=list[1]:
  y=x%k
z=k-y
if z >=y:
  print(y)
else:
  print(z)
  

Fixed code:
list=list(map(int,input().split()))
x=list[0]
k=list[1]
if list[0]>=list[1]:
  x=x%k
z=abs(k-x)
if z >=x:
  print(x)
else:
  print(z)
Buggy code:
N, K = map(int, input().split())
n_1 = N - (K * (N // K))
n_2 = abs(n - K)
print(min(n_1, n_2))

Fixed code:
N, K = map(int, input().split())
n_1 = N - (K * (N // K))
n_2 = abs(n_1 - K)
print(min(n_1, n_2))
Buggy code:
import math

#n,k
n,k = (int(x) for x in input().split())

b = n % k

print(b)

#c = abs(k-b)

if b < c:
    ans = b
else:
    ans = c

print(ans)

Fixed code:
import math

#n,k
n,k = (int(x) for x in input().split())

b = n % k

#print(b)

c = abs(k-b)

if b < c:
    ans = b
else:
    ans = c

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

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

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

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

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

print(min)


Fixed code:
n,k = map(int, input().split())
min = n + 1
if n >= k:
    n = n % k
    
while True:
    if n < min:
        min = n
        n = abs(n - k)
    else:
        break

print(min)
Buggy code:
line1 = input().split()
n = int(line1[0])
k = int(line1[1])

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

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


Fixed code:
a,b=map(int,input().split())
print(min(a%b,b-a%b))
Buggy code:
nk=list(map(int,input().split(' ')))
while(True):
    if abs(nk[0]-nk[1])<nk[0]:
        nk[0]=abs(nk[0]-nk[1])
    else:
        break
print(nk[0])

Fixed code:
nk=list(map(int,input().split(' ')))
nk[0]=nk[0]%nk[1]
while(True):
    if abs(nk[0]-nk[1])<nk[0]:
        nk[0]=abs(nk[0]-nk[1])
    else:
        break
print(nk[0])
Buggy code:
nk = list(map(int,input().split()))
n = nk[0]
k = nk[1]

amari = n % k

if amari == 0:
    ans = k
else:
    
    if amari <= k/2:
        ans = amari
    else:
        ans = -(amari - k)

print(ans)

Fixed code:
nk = list(map(int,input().split()))
n = nk[0]
k = nk[1]

amari = n % k

if amari == 0:
    ans = 0

else:
    if amari <= k/2:
        ans = amari
    else:
        ans = -(amari - k)

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

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

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

pre_value = n+1
tmp = n
a = n / k 
tmp = n - a*k 
while tmp < pre_value:
    pre_value = tmp
    tmp = abs( tmp - k)
    
print(pre_value)    

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

pre_value = n+1
tmp = n
a = n // k 
tmp = n - a*k 
while tmp < pre_value:
    pre_value = tmp
    tmp = abs( tmp - k)
    
print(pre_value)
Buggy code:
n, k = map(int, input().split())

ans = min(n % k, k - abs(n - k))

print(ans)

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())
x = N
while x > K/2:
  x = abs(K-x)
print(x)

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

while x > K/2:
    x = abs(K-x)

print(x)
Buggy code:
N,K=map(int, input().split())
a=N%K
print(a,K-a)

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

Fixed code:
n,k = map(int,input().split())
ans = n
ans = min(ans,n%k)
ans = min(ans,abs(k-n%k))
print(ans)
Buggy code:
n,k=map(int,input().split())
print(min(n%k,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, N-N%K))

Fixed code:
N,K=map(int,input().split())
print(min(N%K,K-N%K))
Buggy code:
N, K = list(map(lambda n: int(n), input().split(" ")))
 
while N <= int(K/2):
  N = min([abs(N-K), N % K])

print(N)

Fixed code:
N, K = list(map(lambda n: int(n), input().split(" ")))
 
while N > int(K/2):
  N = min([abs(N-K), N % K])

print(N)
Buggy code:
import sys
import math
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    if N < K:
        print(N)
    N %= K
    print(min(N, abs(N-K)))


if __name__ == '__main__':
    main()


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


def main():
    N, K = map(int, input().split())
    N %= K
    print(min(N, abs(N-K)))


if __name__ == '__main__':
    main()
Buggy code:
n , k = map(int,input().split())

if(n%k == 0):
        
    g = n//k
        
    print(n - (g*k))
else:
    g = n//k
    ans = n - (g*k)
    print(abs(ans - k))
        

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

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

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

m = 10**18
while True:
    n = min(n, abs(n-k)) 
    if n < m:
        m = n
    else:
        break

print(m)

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

m = 10**18
n = n % k
while True:
    n = min(n, abs(n-k)) 
    if n < m:
        m = n
    else:
        break

print(m)
Buggy code:
def main():
  n,k = [int(x) for x in input().split()]
  return n%k

print(main())

Fixed code:
def main():
  n,k = [int(x) for x in input().split()]
  return min(n%k, k-n%k)

print(main())
Buggy code:
def absolute(N,K):
    return abs(N-K)
    
N,K=map(int,input().split())
N=N%K
valuelist = [N%K]

for i in range (0,1):
    i+=1
    N=absolute(N,K)
    valuelist.append(absolute(N,K))
    
   
print(min(valuelist))


Fixed code:
def absolute(N,K):
    return abs(N-K)
    
N,K=map(int,input().split())
N=N%K
valuelist = [N%K]

for i in range (0,pow(10,1)):
    i+=1
    N=absolute(N,K)
    valuelist.append(absolute(N,K))
    
print(min(valuelist))
Buggy code:
N, K =map(int,input().split())
r = N % K
print(min(r,abs(r-k)))


Fixed code:
N, K =map(int,input().split())
r = N % K
print(min(r,abs(r-K)))
Buggy code:
n,k = map(int,input().split())
print(n%abs(n-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())
if n>=k:n%=k
print(min(k,k-n))

Fixed code:
n,k=map(int,input().split())
if n>=k:n%=k
print(min(n,k-n))
Buggy code:
import sys
n, k = map(int, sys.stdin.buffer.read().split())
rem = n % k
print(min(rem, k - rem)

Fixed code:
import sys
n, k = map(int, sys.stdin.buffer.read().split())
rem = n % k
print(min(rem, k - rem))
Buggy code:
N, K = map(int, input().split(' '))

def absdiff(x, K):
    return abs(x - K)

def culc(N, K):
    if K == 1:
        print(0)
        return

    if N*2 == K:
        print(N)
        return

    x = N
    min = x
    while min >= x:
        print(min, x)
        min = x
        x = absdiff(x, K)

    print(min)
    return


culc(N, K)


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

def absdiff(x, K):
    return abs(x - K)

def culc(N, K):
    if K == 1:
        print(0)
        return

    if N*2 == K:
        print(N)
        return

    if N%K == 0:
        print(0)
        return

    x = N % K
    min = x
    while min >= x:
        #print(min, x)
        min = x
        x = absdiff(x, K)
        if min == 1:
            break

    print(min)
    return


culc(N, K)