ZhenlongDai/ACPR huggingface dataset:
Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n % k
  while ans > abs(n-k):
    n = abs(n - k)
    ans = min(n, ans)
  print(ans)

Failing test case input:
74 47

Expected output:
20


Actual output:
27


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n % k
  
  while ans > k
    n = abs(ans - k)
    ans = min(n, ans)
  print(ans)

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
N, K = map(int, input().split())
if N == K:
    ans = 0
elif N < K:
    ans = N
else:
    ansmin = N-K*math.ceil(N/K)
    ansmax = K-ansmin
    ans = min(abs(ansmin), abs(ansmax))
print(ans)


Failing test case input:
56 84

Expected output:
28


Actual output:
56


Fixed submission (verdict: Accepted):
import math
N, K = map(int, input().split())
if N == K:
    ans = 0
elif N < K:
    ans=min(N,K-N)
else:
    ansmax = N%K
    ansmin = K-ansmax
    ans = min(ansmin, ansmax)
print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())

r = n%k
w = r%k
print(min(r,w))

Failing test case input:
36 53

Expected output:
17


Actual output:
36


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())

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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=(int(i) for i in input().split())
print(n%k)

Failing test case input:
17 22

Expected output:
5


Actual output:
17


Fixed submission (verdict: Accepted):
n,k=(int(i) for i in input().split())
print(min(n%k,(((n

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

if N >= K:
    print(N % K)
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))


Failing test case input:
70 44

Expected output:
18


Actual output:
26


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())











if N == K:
    print(0)

elif N > K:
    val = N % K
    print(min(abs(val), abs(val-K)))
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N,K = map(int,input().split())
    
    if N==K:
        ans = 0
    elif N<K:
        ans = N
    else:
        ans = N%K
        ans = min(ans, K-ans)

    print(ans)
    return

if __name__ == "__main__":
    main()

Failing test case input:
17 22

Expected output:
5


Actual output:
17


Fixed submission (verdict: Accepted):
def main():
    N,K = map(int,input().split())
    
    if N==K:
        ans = 0
    elif N<K:
        ans = min(-N+K,N)
    else:
        ans = N%K
        ans = min(ans, K-ans)

    print(ans)
    return

if __name__ == "__main__":
    main()
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()

Failing test case input:
74 47

Expected output:
20


Actual output:
27


Fixed submission (verdict: Accepted):
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()

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split(' '))

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

print(_min)

Failing test case input:
36 53

Expected output:
17


Actual output:
36


Fixed submission (verdict: Accepted):
N, K = map(int, input().split(' '))
_min = min(abs(N%K), abs(K-N%K))

print(_min)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
diff = abs(K - N)

if N < K:
    print(N)
    exit()

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



Failing test case input:
17 22

Expected output:
5


Actual output:
17


Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline

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

if N < K:
    print(min(N, K - N))
    exit()

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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)



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)

Failing test case input:
14 23

Expected output:
9


Actual output:
14


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)



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)))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 

sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

d = defaultdict(int)
res = N
x = N
while 1:
    val = res
    x = abs(res-val)
    y = abs(res-K)
    d[x] += 1
    d[y] += 1
    
    res = min(res, x, y)
    if d[x] > 10:
        break
print(res)



Failing test case input:
1000010011000001001 2

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 

sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

d = defaultdict(int)
res = N
x = N
while 1:
    x = res%K
    y = abs(res-K)
    
    res = min(res, x, y)
    d[res] += 1
    
    if d[res] > 10:
        break
print(res)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

if N == K:
    print(0)
    exit(0)
elif N < K:
    print(N)
    exit(0)

ans = []
before = abs(N - K)
N = N % K
for i in range(10000):
    ze = abs(N - K)
    ans.append(ze)
    before = ze
    N = ze
print(min(ans))


Failing test case input:
56 84

Expected output:
28


Actual output:
56


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())








ans = []
before = abs(N - K)
N = N % K
for i in range(10000):
    ze = abs(N - K)
    ans.append(ze)
    before = ze
    N = ze
print(min(ans))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

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

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

Failing test case input:
70 44

Expected output:
18


Actual output:
1


Fixed submission (verdict: Accepted):
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)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N , K = map(int , input().split())
mini = N

for i in range(10000):
    x = abs(mini - K)
    if x < mini:
        mini = x
    

print(mini)

Failing test case input:
1000000010000011001 1

Expected output:
0


Actual output:
1000000010000001001


Fixed submission (verdict: Accepted):
N , K = map(int , input().split())

mini = N % K

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

print(mini)
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
l = []
ans = 1
if(n%m == 0):
  ans=0
else:
  for x in (0,1000000000000000000):
    n = abs(n%m)
    l.append(n)
  l.sort()
  ans = min(n,l[0])
print(ans)

Failing test case input:
74 47

Expected output:
20


Actual output:
27


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
l = []
ans = 1
if(n%m == 0):
  ans=0
else:
  for x in (0,1000000000000000000):
    n = abs(n%m)
    l.append(n)
  l.sort()
  ans = min(m-n,l[0])
print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = (int(i) for i in input().split())
if k > n:
    print(n)
elif n % k == 0:
    print(0)
else:
    q = n % k
    q = abs(q-k)
    print(min(k, q))

Failing test case input:
12 23

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
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
    print(min(p, q))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

N,K = [int(i) for i in input().split(" ")]

tmp = N

if N >= K:
    if N % K == 0:
        print(0)
        sys.exit()
    else:
        K = N 

while True:
    print(N)
    if abs(N - K) < tmp:
        N = abs(N - K)
    else:
        print(tmp)
        sys.exit()
    tmp = N
  

Failing test case input:
22 50

Expected output:
22


Actual output:
22
22


Fixed submission (verdict: Accepted):
import sys

N,K = [int(i) for i in input().split(" ")]

tmp = N

if N >= K:
    if N % K == 0:
        print(0)
        sys.exit()
    else:
        N = N % K

while True:
    
    if abs(N - K) < tmp:
        N = abs(N - K)
    else:
        print(tmp)
        sys.exit()
    tmp = N

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())

if n==k:
    ans = 0
elif n<k:
    ans = n
else:
    ans = k-(n%k)

if n>k and k==1:
    ans -= 1

print(ans)

Failing test case input:
12 23

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())

if n==k:
    ans = 0
elif n<k:
    ans = min(n, abs(n-k))
else:
    if n%k==0:
        ans=0
    else:
        ans = min(n%k, k-(n%k))

print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map( int, input().split() )

now_N = 10 ** 19
while True:
  N = min( abs( N % K ), now_N )
  if now_N == N:
    break
  now_N = N
print( now_N )

Failing test case input:
12 23

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
N, K = map( int, input().split() )
 
now_N = 10 ** 19
while True:
  N = min( abs( N % K ),abs( K - N ), now_N )
  if now_N == N:
    break
  now_N = N
print( now_N )
Problem: p02719
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


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

if n == 0:
    print(0)
elif k == 1:
    print(1)
elif n == k:
    print(0)
else:
    if n > k:
        r = n % k
        if r == 0:
            print(0)
        else:
            print(abs(r - k))
    else:
        n = abs(n - k)
        n = abs(n - k)
        print(n)


Failing test case input:
44 30

Expected output:
14


Actual output:
16


Fixed submission (verdict: Accepted):


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

if n == 0 or n == k:
    print(0)
elif k == 1:
    print(0)
else:
    if n > k:
        r = n % k
        if r == 0:
            print(0)
        else:
            n_1 = abs(r - k)
            n_2 = abs(n_1 - k)
            print(min(n_1, n_2))
    else:
        n_1 = abs(n - k)
        n_2 = abs(n_1 - k)
        print(min(n_1, n_2))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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

num=math.floor(n/k)
be=abs(n-num*k)
af=abs(n-num*k-k)

print(be if be<=af else af) 

Failing test case input:
1000010010000010001 1

Expected output:
0


Actual output:
16


Fixed submission (verdict: Accepted):
import math

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

be=n%k
af=abs(k-be)

print(be if be<=af else af)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = list(map(int, input().split()))

tmp = N % K

if tmp == 0:
    print(0)
elif N <= tmp:
    print(N)
elif tmp < (K - tmp):
    print(tmp)
else:
    print(abs(K - tmp))


Failing test case input:
36 53

Expected output:
17


Actual output:
36


Fixed submission (verdict: Accepted):
N, K = list(map(int, input().split()))

tmp = N % K

if tmp == 0:
    print(0)
elif N < tmp:
    print(N)
elif tmp < (K - tmp):
    print(tmp)
else:
    print(abs(K - tmp))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = list(map(int, input().split()))
reminder = n % k

print(reminder)


Failing test case input:
12 23

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
n, k = list(map(int, input().split()))
reminder = n % k
s = abs(reminder - k)

res = min(reminder, s)
print(res)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 <= N-K:
        print(N)
    else:
        print(K-N)


Failing test case input:
22 50

Expected output:
22


Actual output:
28


Fixed submission (verdict: Accepted):
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)
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
Abs = abs(N - K)
if N <= K:
    while True:
        if N > Abs:
            N = Abs
        else:
            break
else:
    N = N % K + K
    while True:
        if N > Abs:
            N = Abs
        else:
            break
print(N)

Failing test case input:
1000000000000010000 2

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
if N <= K:
    while True:
        if N > abs(N - K):
            N = abs(N - K)
        else:
            break
else:
    N = N % K + K
    while True:
        if N > abs(N - K):
            N = abs(N - K)
        else:
            break
print(N)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys

def get_abs(N, K):
  return abs(N-K)

N, K = map(int, input().split())
if K == 1:
  print(0)
  sys.exit()
  
if N/K > 1:
  N = N - (N / K) * K
a = abs(N-K)
while abs(a - K) < a:
  a = abs(a-K)

print(int(a))

Failing test case input:
1000010011000001001 2

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):

import sys

N, K = map(int, input().split())
if K == 1:
  print(0)
  sys.exit()
  
if N / K > 1:
  N = N - int(N / K) * K
a = abs(N-K)
while abs(a - K) < a:
  a = abs(a-K)

print(int(a))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

if n < k:
    print(n)
elif k == 1 or (k % 2 == 0 and n % 2 == 0):
    print(0)
elif (k % 2 == 0 and n % 2 == 1) or (n % 2 == 0 and k % 2 == 1):
    print(1)


Failing test case input:
17 22

Expected output:
5


Actual output:
17


Fixed submission (verdict: Accepted):

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

Problem: p02719
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


t = input().split()
n = int(t[0])
k = int(t[1])

a = 0
if n%k == 0:
    a = 0
elif n < k:
    a = n
else:
    a = abs(k-n%k)
print(a)

Failing test case input:
103 44

Expected output:
15


Actual output:
29


Fixed submission (verdict: Accepted):


t = input().split()
n = int(t[0])
k = int(t[1])

a = 0
if n%k == 0:
    a = 0
else:
    e = n%k
    a = abs(k-e)
    if a > e:
        a = e
print(a)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())

mod = n % k

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


Failing test case input:
16 45

Expected output:
16


Actual output:
29


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
 
mod = n % k
 
if mod > k - mod:
  print(k-mod)
else:
  print(mod)
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N, K = map(int, input().split())
if N == 1 or N == 0 or K == 1 or N == K:
    print(0)
    sys.exit()

if N > K:
    N = N%K
elif K > N:
    K = K%N

ans = [N]
for _ in range(10):
    ans.append(abs(N-K))
    N = abs(N-K)

print(min(ans))


Failing test case input:
17 22

Expected output:
5


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
N, K = map(int, input().split())
if N == 0 or K == 1 or N == K:
    print(0)
    sys.exit()

if N > K:
    N = N%K




ans = [N]
for _ in range(100):
    ans.append(abs(N-K))
    N = abs(N-K)

print(min(ans))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
m = n % k
print(m, abs(m-k))

Failing test case input:
42 84

Expected output:
42


Actual output:
42 42


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
m = n % k
print(min(m, abs(m-k)))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = (int(x) for x in input().split())
print(N % K)

Failing test case input:
56 84

Expected output:
28


Actual output:
56


Fixed submission (verdict: Accepted):
N,K = (int(x) for x in input().split())
a = N % K
print(min((a, K-a)))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())

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

print(x)


Failing test case input:
14 23

Expected output:
9


Actual output:
14


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())

if N>=K:
    amari = N % K
    X = K - amari
    if X > amari:
        x = amari
    else :
        x = X
else:
    if N >= (K-N):
        x = K-N
    else:
        x = N        


print(x)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

if n < k:
    print(n)
elif k == 1 or n == 0 or (k % 2 == 0 and n % 2 == 0):
    print(0)
elif (k % 2 == 0 and n % 2 == 1) or (n % 2 == 0 and k % 2 == 1):
    print(1)


Failing test case input:
65 44

Expected output:
21


Actual output:
1


Fixed submission (verdict: Accepted):

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

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n, k = map(int, input().split())
    if n <= k:
        print(n)
    else:
        print(n%k)
    return 0

if __name__ == "__main__":
    solve()

Failing test case input:
56 84

Expected output:
28


Actual output:
56


Fixed submission (verdict: Accepted):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n, k = map(int, input().split())
    print(min(n%k, k-(n%k)))
    return 0

if __name__ == "__main__":
    solve()
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())
r=N%K
print(max(r,K-r))

Failing test case input:
44 30

Expected output:
14


Actual output:
16


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
r=N%K
print(min(r,K-r))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    q, mod = divmod(N, K)
    if q == 0:
        print(mod)
    else:
        print(min(q, mod))



if __name__ == '__main__':
    main()


Failing test case input:
103 44

Expected output:
15


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    q, mod = divmod(N, K)
    print(min(mod, abs(K - mod)))


if __name__ == '__main__':
    main()

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = input().split(' ')
n = int(n)
k = int(k)

if k == 1:
  print(0)
elif n < k:
  r1 = n
  r2 = n - k
  if r2 < 0:
    r2 *= -1
  print(min(r1,r2))
else:
  r1 = n 
  r2 = n - k
  if r2 < 0:
    r2 *= -1
  print(min(r1,r2))

Failing test case input:
1000000000100010000 2

Expected output:
0


Actual output:
1000000000100009998


Fixed submission (verdict: Accepted):
n, k = input().split(' ')
n = int(n)
k = int(k)

if k == 1 or n == 0:
  print(0)
elif n < k :
  r1 = n
  r2 = n - k
  if r2 < 0:
    r2 *= -1
  print(min(r1,r2))
else:
  r1 = n % k
  r2 = r1 - k
  if r2 < 0:
    r2 *= -1
  print(min(r1,r2))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
nn, kk = input().split(" ")
n = int(nn)
k = int(kk)
 
remain = n % k
if( kk=="1" ):
  print(0)
elif( remain == 0 ):
  print(remain)
else:
  print( min(abs( remain - k), abs(k-remain) ))

Failing test case input:
16 45

Expected output:
16


Actual output:
29


Fixed submission (verdict: Accepted):
nn, kk = input().split(" ")
n = int(nn)
k = int(kk)
 
remain = n % k
if( kk=="1" ):
  print(0)
elif( remain == 0 ):
  print(remain)
else:
  print( min(abs( remain - k), abs(abs(remain-k)-k) ))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
if n % k == 0:
    print(0)
else:
    print(min(n, n % abs(n - k)))


Failing test case input:
0001010001000001001 2

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
if n % k == 0:
    print(0)
else:
    print(min(n, n % k, abs(k - (n % k))))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N,K = map(int, input().split())
ans = N
for i in range(int(N/K)-2,math.ceil(N/K)+2):
    ans = min(ans,abs(N-K*i))

print(ans)

Failing test case input:
1000000010000011001 1

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())

x = abs(N - K*(int(N/K)-1))
ans = N

for i in range(0,100000):
    x = abs(x-K)
    ans = min(ans,x)

print(ans)

Problem: p02719
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


t = input().split()
n = int(t[0])
k = int(t[1])

a = 0
if k == 1:
    a = 0
elif n < k:
    a = n
elif n%k == 0:
    a = 0
else:
    a = abs(k-n%k)
print(a)

Failing test case input:
30 23

Expected output:
7


Actual output:
16


Fixed submission (verdict: Accepted):


t = input().split()
n = int(t[0])
k = int(t[1])

a = 0
if n%k == 0:
    a = 0
else:
    e = n%k
    a = abs(k-e)
    if a > e:
        a = e
print(a)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b=map(int,input().split())
ans=[a]
for i in range(10000):
    ans.append(abs(ans[i]-b))
print(0 if b==1 else min(ans))

Failing test case input:
1000000010000010000 2

Expected output:
0


Actual output:
1000000009999990000


Fixed submission (verdict: Accepted):
a,b=map(int,input().split())
ans=[a,a%b]
for i in range(10000):
    ans.append(abs(ans[i]-b))
print(min(ans))

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
print(n%k)

Failing test case input:
56 84

Expected output:
28


Actual output:
56


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
c=n%k
print(min(c,k-c))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().strip().split())

min_n = 1000000000000000000000000000
for i in range(1000):
    n %= k
    n = abs(n - k)
    min_n = min(min_n, n)

print(min_n)


Failing test case input:
1000000000000000000 1

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
n, k = map(int, input().strip().split())

min_n = 1000000000000000000000000000
for i in range(1000):
    if n > k:
        n %= k
    n = abs(n - k)
    min_n = min(min_n, n)

print(min_n)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
i = [int(i) for i in input().split()]

n = i[0]
k = i[1]

print(n % k)

Failing test case input:
70 44

Expected output:
18


Actual output:
26


Fixed submission (verdict: Accepted):
i = [int(x) for x in input().split()]
n = i[0]
k = i[1]

t = n % k
t2 = k -t

print(min(t, t2))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, K = [int(x) for x in input().split()]

if K > n:
    res = n
elif n % K == 0:
    res = 0
else:
    res = K


Failing test case input:
1001000010000010000 2

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
n, K = [int(x) for x in input().split()]

res = 0
if n % K > abs((n % K) - K):
    res = abs((n % K) - K)
else:
    res = n % K
    
print (res)

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
def resolve():
    N,K = map(int,input().split())
    A = math.gcd(N,K)
    if N == 1 or K == 1:
        print(0)
    else: 
        print(A)
resolve()

Failing test case input:
65 44

Expected output:
21


Actual output:
1


Fixed submission (verdict: Accepted):
def resolve():
    N,K = map(int,input().split())
    A = N % K
    if K == 1:
        print(0)
    else: 
        print(min(A,K-A))
resolve()

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
a = abs(N-K)
print(min(a, abs(a-K)))

Failing test case input:
1000000000000010000 1

Expected output:
0


Actual output:
1000000000000009998


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
a = abs(N%K)
print(min(a, abs(a-K)))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b=map(int,input().split())
a=a-10**str(a).count('0')
ans=[a]
for i in range(10000):
  ans.append(abs(ans[i]-b))
print(min(ans))

Failing test case input:
0001010001000001001 1

Expected output:
0


Actual output:
1009900999991001


Fixed submission (verdict: Accepted):
a,b=map(int,input().split())
ans=[a,a%b]
for i in range(10000):
    ans.append(abs(ans[i]-b))
print(min(ans))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
diff = abs(K - N)

if N < K:
    print(N)
    exit()
if N % K == 0:
    print(0)
else:
    print(K - N%K)



Failing test case input:
14 23

Expected output:
9


Actual output:
14


Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline

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

if N < K:
    print(min(N, K - N))
    exit()

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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
print(min(n%k,k-n))

Failing test case input:
1000000010000111001 1

Expected output:
0


Actual output:
-1000000010000111000


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
print(min(n%k,k-n%k))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int, input().split())
l=[]


if(n!=k):
  i = n - k * int(n/k)
  l.append(abs(i-k))
  l.append(abs(l[0]-k))
  print(min(l))


Failing test case input:
1000010011000001001 2

Expected output:
1


Actual output:
23


Fixed submission (verdict: Accepted):
n,k=map(int, input().split())
l=[]

i = n % k 
l.append(abs(i-k))
l.append(abs(l[0]-k))
print(min(l))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
ans=(n % m)
ans=min(ans,abs(n-m))
print(ans)

Failing test case input:
17 9

Expected output:
1


Actual output:
8


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
ans=(n % m)
ans=min(abs(ans),abs(ans-m))
print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

before = N - int(N / K) * K
after = abs(before - K)

if before > after:
    print(after)
else:
    print(before)

Failing test case input:
1000010010000010001 1

Expected output:
0


Actual output:
16


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())

before = abs(N - int(N / K) * K)
before2 = N % K
after = abs(before2 - K)

if before2 > after:
    print(after)
else:
    print(before2)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
17 9

Expected output:
1


Actual output:
8


Fixed submission (verdict: Accepted):
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))

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n % k + k
  while ans > abs(n-k):
    n = abs(n - k)
    ans = min(n, ans)
  print(ans)

Failing test case input:
1000010011000001001 2

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())

if n % k == 0:
  print(0)
else: 
  ans = n % k
  
  while ans > k
    n = abs(ans - k)
    ans = min(n, ans)
  print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
print(min([N, N%K] + (K < N)*[N-N%K]))

Failing test case input:
12 23

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
print(min([N, N%K, abs(K-N%K)]))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)



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(n%k)

Failing test case input:
70 44

Expected output:
18


Actual output:
26


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)



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)))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

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


Failing test case input:
12 23

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

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

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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
44 30

Expected output:
14


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int, input().split())
if K==1:
    print(0)
    exit()
if K==2:
    if N%2==0:
        print(0)
        exit()
    else:
        print(1)
        exit()

def func(x,K):
    tmp=x-K
    if tmp<0:
        tmp*=(-1)
    return tmp












y=N/K
N=func(N,K*y)

ans = N
while(True):
    N=func(N,K)
    if N<ans:
        ans=N
    else:
        break
print(ans)


Failing test case input:
30 23

Expected output:
7


Actual output:
0.0


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
if N==0:
    print(0)
    exit()
if K==1:
    print(0)
    exit()
if K==2:
    if N%2==0:
        print(0)
        exit()
    else:
        print(1)
        exit()

def func(x,K):
    tmp=x-K
    if tmp<0:
        tmp*=(-1)
    return tmp

if (N>K):
    y=int(N/K)
    N=func(N,K*y)

ans = N
while(True):
    N=func(N,K)
    if N<ans:
        ans=N
    else:
        break
print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

if N < K:
    ans = N
elif N == K or K == 1:
    ans = 0
else:
    a = N % K
    ans = abs(a - K)
    if a <= ans:
        ans = a

print(str(ans))


Failing test case input:
36 53

Expected output:
17


Actual output:
36


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())


if N == K or K == 1:
    ans = 0
else:
    a = N % K
    ans = abs(a - K)
    if a <= ans:
        ans = a

print(str(ans))
Problem: p02719
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
import math

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





n_start = math.floor(n / k)

n = n - n_start*k




while True:
    min_n = n
    n = abs(n-k)
    
    if min_n > n:
        min_n = n
    else:
        break
print(min_n)


Failing test case input:
1000010011000001001 2

Expected output:
1


Actual output:
-23


Fixed submission (verdict: Accepted):
import sys
import math

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






n = n % k

while True:
    min_n = n
    n = abs(n-k)
    
    if min_n > n:
        min_n = n
    else:
        break
print(min_n)

Problem: p02719
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k = map(int, input().split())
tmpNum = n
subtraction = n
if n % k == 0:
  print(0)
else:
  tmp = int(n/k)
  subtraction = n - (tmp*k)
  while(1):
    subtraction = abs(subtraction-k)
    print(subtraction,tmpNum)
    if subtraction < tmpNum:
      tmpNum = subtraction
    else:
      break
  print(tmpNum)


Failing test case input:
103 44

Expected output:
15


Actual output:
29 103
15 29
29 15
15


Fixed submission (verdict: Accepted):
n,k = map(int, input().split())
tmpNum = n
subtraction = n
if n % k == 0:
  print(0)
else:
  tmp = int(n/k)
  subtraction = n - (tmp*k)
  while(1):
    subtraction = abs(subtraction-k)
    if subtraction < tmpNum:
      tmpNum = subtraction
    else:
      break
  print(tmpNum)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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



y = abs(N - K)
N = y
y2 = abs(N - K)
c=1
dif = (y, y2)

if dif[c-1] <= dif[c]:
    print(dif[-1])
    
if dif[c-1] > K:

    dif += (dif[c-1]%K,)
    c += 1

while dif[c-1] > dif[c]:

    yy = abs(dif[c] - K)
    dif += (yy,)
    c += 1


print(min(dif))
    
    

Failing test case input:
42 84

Expected output:
42


Actual output:
42
42


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())



y = abs(N - K)
N = y
y2 = abs(N - K)
c=1
dif = (y, y2)

if dif[c-1] < dif[c]:
    dif += (dif[-1],)
    
if dif[c-1] > K:

    dif += (dif[c-1]%K,)
    c += 1

while dif[c-1] > dif[c]:

    yy = abs(dif[c] - K)
    dif += (yy,)
    c += 1


print(min(dif))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N, K = map(int, input().split())
if N == 1 or N == 0 or K ==1:
    print(0)
    sys.exit()

if N > K:
    N = N%K
elif K > N:
    K = K%N

for _ in range(10):
    N = min(abs(N-K), N)
print(N)


Failing test case input:
17 22

Expected output:
5


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
N, K = map(int, input().split())
if N == 0 or K == 1 or N == K:
    print(0)
    sys.exit()

if N > K:
    N = N%K




ans = [N]
for _ in range(100):
    ans.append(abs(N-K))
    N = abs(N-K)

print(min(ans))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import math
def my_round(val, digit=0):
    p = 10 ** digit
    return (val * p * 2 + 1) 

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

Failing test case input:
17 9

Expected output:
1


Actual output:
4.222222222222222


Fixed submission (verdict: Accepted):

import math
def my_round(val, digit=0):
    p = 10 ** digit
    return (val * p * 2 + 1) 

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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())

right=N%K
left=int(N/K+1)*K-N


if right>left:
    print(left)
else:
    print(right)

Failing test case input:
1000010010000010000 2

Expected output:
0


Actual output:
-16


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())

right=N%K
left=K-N%K


if right>=left:
    print(int(left))
else:
    print(int(right))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int, input().split())
ans = 0


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



print(ans)


Failing test case input:
44 30

Expected output:
14


Actual output:
0


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
ans = 0



 
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)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

if N<= K:
    print(min(N,K-N))
else:
    N = N - math.floor(N/K)*K 
    print(min(N, K-N)) 

Failing test case input:
1000010010000010000 2

Expected output:
0


Actual output:
-14


Fixed submission (verdict: Accepted):


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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
s = input().split()
t = [int(p) for p in s]

N = t[0]
K = t[1]

p = int(N/K)
a = N - p * K
b = abs(a - K)
print('N:{}, K:{}, p:{}, a:{}, b:{}'.format(N,K,p,a,b))

Failing test case input:
1001010011000000001 2

Expected output:
1


Actual output:
N:1001010011000000001, K:2, p:500505005500000000, a:1, b:1


Fixed submission (verdict: Accepted):

from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
s = input().split()
t = [int(p) for p in s]

N = t[0]
K = t[1]



a = Decimal(N % K)
b = Decimal(K - a)

print(min(a,b))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
aa=list(map(int,input().split()))
n=aa[0]
k=aa[1]
minn=n%k
print(abs(min(n%k,(n%k)-k)))

Failing test case input:
33 84

Expected output:
33


Actual output:
51


Fixed submission (verdict: Accepted):
aa=list(map(int,input().split()))
n=aa[0]
k=aa[1]
minn=n%k
print(min(n%k,abs((n%k)-k)))

Problem: p02719
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math


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


if __name__ == '__main__':
    main()


Failing test case input:
30 23

Expected output:
7


Actual output:
1


Fixed submission (verdict: Accepted):
def main():
    n, k = map(int, input().split())
    t = n % k
    print(min(t, k - t))


if __name__ == '__main__':
    main()

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, K = map(int,input().split())

prev = -1
while prev != min(N,K):
  prev = min(N,K)
  if N == K or N == 0 or K == 0:
    prev = 0
    break
  if N > K:
    N = N % K
  else:
    K = K % N
  
print(prev)

Failing test case input:
30 23

Expected output:
7


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int,input().split())

if N > K:
  N = N % K

min_N = float("inf")
while min_N != N:
  min_N = min(N,min_N)
  if N == K or N == 0 or K == 0:
    print(0)
    exit(0)
  
  N = abs(N - K)
  
print(min_N)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
16 45

Expected output:
16


Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = list(map(int, input().split()))

tmp = N % K

if tmp == 0:
    print(0)
elif N <= tmp:
    print(N)
else:
    print(abs(K - tmp))


Failing test case input:
36 53

Expected output:
17


Actual output:
36


Fixed submission (verdict: Accepted):
N, K = list(map(int, input().split()))

tmp = N % K

if tmp == 0:
    print(0)
elif N < tmp:
    print(N)
elif tmp < (K - tmp):
    print(tmp)
else:
    print(abs(K - tmp))

Problem: p02719
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k=map(int,input().split())
if n==0 or k==0:
    print(0)
    exit()

elif n%k==0:
    print(0)
    exit()

else:
    print(n%(abs(n-k)))



Failing test case input:
42 84

Expected output:
42


Actual output:
0


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
amari=n%k
if n==0:
    print(0)
    exit()

elif n%k==0:
    print(0)
    exit()


else:
    print(min(amari,k-amari))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())

if k > n:
  if abs(k-n)<=n:
    print(abs(k-n))
  else:
    print(n)
  
else:
  amari = n%k
  amari_minus = amari -k
  if abs(amari)<= (amari_minus):
    print(abs(amari))
  else:
    print(abs(amari_minus))


Failing test case input:
1000000000000010000 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())

if n==k:
  print(0)

elif k > n:
  if k-n<=n:
    print(k-n)
  else:
    print(n)
  
else:
  amari = n%k
  com3 = k -amari
  if amari<= com3:
    print(amari)
  else:
    print(com3)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

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

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

Failing test case input:
16 45

Expected output:
16


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

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

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

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, K = map(int, input().split())
    syo = int(N / K)    
    amari = N % K
    tmp = K * (syo + 1) - N

    if amari <= tmp:
        print(amari)
    else:
        print(tmp)

main()

Failing test case input:
1000000010000010000 2

Expected output:
0


Actual output:
-14


Fixed submission (verdict: Accepted):
def main():
    import math
    N, K = map(int, input().split())
    
    
    amari = N % K
    
    tmp = K - amari

    if amari <= tmp:
        print(amari)
    else:
        print(tmp)

main()

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())

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

print(ans)

Failing test case input:
56 84

Expected output:
28


Actual output:
56


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())

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

print(ans)

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

if N == K:
    print(0)

elif N > K:
    if N % K == 0:
        print(0)
    else:
        print(min(N % K, N % (N-K)))
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))


Failing test case input:
44 30

Expected output:
14


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())











if N == K:
    print(0)

elif N > K:
    val = N % K
    print(min(abs(val), abs(val-K)))
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
print(n % k)

Failing test case input:
17 22

Expected output:
5


Actual output:
17


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
print(min(n % k, abs(n % k - k)))
Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int,input().split())
m = int(n/k)
pos_min = n - m*k
min_one = abs(pos_min -k)
print(min(pos_min,min_one))


Failing test case input:
1000000010000010000 2

Expected output:
0


Actual output:
14


Fixed submission (verdict: Accepted):
n, k = map(int,input().split())
pos_min = n % k
min_one = abs(pos_min-k)
print(min(pos_min,min_one))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int, input().split(' '))
x = N - int(N/K) * K
x1 = K - x
if x > x1:
  print(x1)
else:
  print(x)

Failing test case input:
1000010010000010001 1

Expected output:
0


Actual output:
-16


Fixed submission (verdict: Accepted):
N,K = map(int, input().split(' '))
x = N % K
x1 = K - x
if x > x1:
  print(x1)
else:
  print(x)

Problem: p02719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
print(max(n%k,k-n%k))

Failing test case input:
17 9

Expected output:
1


Actual output:
8


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
print(min(n%k,k-n%k))

Problem: p02719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n
    if n < k-n:
        print(n)
    else:
        print(k-n)

Failing test case input:
1000010010000011001 1

Expected output:
0


Actual output:
-1000010010000011000


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)