TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
# ABC161C

def f(n, k):
    for i in range(10):
        if n < k:
            print(n)
        else:
            m =  n % k
            if m <= k:
                print(m)
            else:
                n = abs(n - k)
                print(k)

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


def f(n, k):
    if n % k == 0:
        print(0)
    else:
        n1 = n % k
        n2 = abs(n1 - k)
        print(min(n1, n2))

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

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=map(int,input().split())
M=N%K
print(min(M,N-M))

N,K=map(int,input().split())
M=N%K
print(min(M,K-M))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import fractions
n,k=map(int,input().split())
if k==1:print(0)
else:print(gcd(n,k))

n,k=map(int,input().split())
if n%k==0:print(0)
else:print(min(k-n%k,n%k))

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k=map(int,input().split())
print(n%k)

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

if n>k:
    print(x%k)
else:
    print(n)


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

if n>k:
    print(x%k)
else:
    print(min(n, x))


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

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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
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)) 

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

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k=map(int,input().split());print(n-k*(-((k-n)//k)))

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = map(int, input().split())

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

print(ans)

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

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

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n=int(input(""))
k=int(input(""))
s=n%k
ss=k-s
if(s<ss):
    print(s)
else:
    print(ss)

l=input("").split(" ")
n=int(l[0])
k=int(l[1])
s=n%k
ss=k-s
if(s<ss):
    print(s)
else:
    print(ss)

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, K = map(int, input().split())

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

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

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

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

if N >= K:
  print(N % K)
else:
  print(N)

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

if K == 0:
  print(N)
else:
  if N >= K:
    kotae1 = abs(N - ((N // K) * K))
    kotae2 = abs(N -((N // K) + 1) * K)
    if kotae1 > kotae2:
      print(kotae2)
    else:
      print(kotae1)

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=map(int,input().split(" "))

for i in range(N//K):
  if abs(N-K)<N:
    N=abs(N-K)
print(N)


N,K = map(int,input().split())
N = N % K
print (min(N,K-N))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
while x>0:
    if (k == 1):
        rlist = [0]
        break
    rlist.append(abs(x-k))
    x = abs(x-k)
    min_n = min(rlist)
    if (min_n == abs(x-k)):break
    if (min_n == 0):break
    if(len(set(rlist)) != len(rlist)):
        break

print(min(rlist))

n, k = map(int, input().split()) 
t = n % k
print(min([t, k-t]))

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
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)

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)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k = map(int, input().split())

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

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

min_num = 10**18+1
flag = True

while flag:
  N = abs(N-K)
  if N < min_num: min_num = N
  else: break
    
return min_num


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

min = 10**18+1
flag = True

while flag==True:
  N = abs(N-K)
  if N < min: min = N
  else: flag == False
    
return min

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

min = 10**18+1
flag = True

while flag==True:
  N = abs(N-K)
  if N < min: min = N
  else: flag = False
    
return min


n,k = map(int,input().aplit())
print(min(n%k,abs(n%k-k)))

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k = map(int,input().split())

print(n % k)

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

ans = n % k
if ans > abs(ans - k):
    print(abs(ans - k))
else:
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = map(int, input().split())
l = n % k

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

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

if n < k:
    print(n)
else:
    if l == 0:
        print(0)
    elif l < k:
        print(l)
    elif l > k:
        print(l - k)

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

print(min(l, abs(l - k)))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = map(int, input().split())

done = []
now = n

while True:
  if now in done:
    break
  done.append(now)
  if now == 0:
    break
  if now%k == 0:
    done.append(0)
    break
  nex = abs((k - (now//k)*k) - now)
  now = nex

print(str(min(done)))

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

done = []
now = n

while True:
  if now in done:
    break
  done.append(now)
  if now == 0:
    break
  if now%k == 0:
    done.append(0)
    break
  nex = abs(k - (now - (now//k)*k))
  now = nex

print(str(min(done)))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k=map(int,input().split())

n=n%k
while n>=k:
  n=abs(n-k)
  
print(int(n))

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

n=n%k
while n>=k/2:
  n=abs(n-k)
  
print(int(n))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = map(int, input().split())

ans = n
all = [n]
if n == 1 or k == 1 or n == 2*k or k == 2*n:
  ans = 0
elif abs(n - k) < n or abs(n - k) < k:
  ans = abs(n - k)
else:
  all = []
  for i in range(2*n):
    n = abs(n - k)
    all.append(n)

  
print(min(ans, min(all)))

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

ans = n
if n == 0 or n == 1 or k == 1 or n == k:
  ans = 0
elif n >= 2*k or k >= 2*n:
  ans = n
else:
  ans = abs(n-k)
  
print(ans)


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

rot = n//k
x = n

if k == 1 or n == k or n%k == 0:
  x = 0
elif rot >= 1:
  x = n - k*rot
  
t = x%k

print(min(t, abs(t-k)))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K = map(int,input().split())
tmp=0
if(N+K)%2==0:
    N=N/2
    K=K/2


if K!=1:
    while N>0:
        tmp =N-K
        if tmp<0:
            print(tmp+K)
            exit(0)
        else:
            N=abs(N-K)
else:
    print(0)

N,K = map(int,input().split())
tmp=0
if K!=1:
    while N>0:
        tmp =N-K
        if tmp<0:
            print(tmp+K)
            exit(0)
        else:
            N=abs(N-K)
else:
    print(0)

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

div =N//K
N=N-div*K

if K!=1:
    while True:
        N=abs(N-K)
        tmp=N
        if abs(N-K)>tmp:
            print(tmp)
            exit(0)
else:
    print(0)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = map(int, input().split())

print((n+k)%k)

n, k = map(int, input().split())
x = (n+k)%k
print(min(x, k-x))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = map(int, input().split())
if n > k:
    print(n%k)
else:
    te = abs(n-k)
    print(min(te, n))

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


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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
a=list(map(int, input().split()))
l=[a[0]]
def d(a,b):
    if a==1 or b==1:
        return 0
    elif a<b:
        if min(l)!=b-a:
            l.append(b-a)
            d(b-a,a)
        else:
            return b-a
    elif b<a:
        if min(l)!=a-b:
            l.append(a-b)
            d(a-b,b)
        else:
            return a-b
print(d(a[0],a[1]))

a=list(map(int, input().split()))
l=[a[0]]
if a[0]==1:
    print(0)
    exit()
elif a[0]==0:
    print(0)
    exit()
elif a[1]==1:
    print(0)
    exit()
def d(a,b):
    if a<b:
        if min(l)>b-a:
            l.append(b-a)
            print(l)
            d(b-a,b)
        else:
            print(min(l))
            exit()
    elif b<a:
        if min(l)>a-b:
            l.append(a-b)
            print(l)
            d(a-b,b)
        else:
            print(min(l))
            exit()
    else:
        print(0)
        exit()
d(a[0],a[1])

a=list(map(int, input().split()))
def d(a,b):
    _1=a%b
    _2=b-(a%b)
    if _1<_2:
        print(_1)
    else:
        print(_2)
d(a[0],a[1])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
# 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))

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=map(int,input().split())
import math
if K>=N:
  N=min(K-N,N)
else:
  N=N-(math.floor(N/K)-1)*K
  N=min(K-N,N)
print(N)

N,K=map(int,input().split())
print(min(abs(N-(K*(N//K))),abs(N-(K*((N//K)+1)))))


Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K = map(int,input().split())

print(N % K) 

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

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
buf = input().split()
n = int(buf[0])
k = int(buf[1])

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

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

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

print(min([c1, c2]))

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, K = map(int, input().split())

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


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

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


Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, m = map(int, input().split())
A = list(map(int, input().split()))
all_vote = sum(A)
cnt = 0
for a in A:
    if a * 4 * m >= all_vote:
        cnt += 1
if cnt >= m:
    print("Yes")
else:
    print("No")

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

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, K = input().split();
N = int(N);
K = int(K);

amari = N % K;

hu = amari - K;

max_N = max(amari,hu);

print(max_N);

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


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


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=map(int,input().split())
from fractions import gcd
g=gcd(N,K)
print(0 if g==K else g)

N,K=map(int,input().split())
print(min(N%K,K-N%K))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
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)


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


Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import math
 
if __name__ == "__main__":
    N, K = map(int, input().split())
    if N == 0:
        ret = 0
        print(int(ret))
        exit(0)
    ret =  N - ((math.ceil(N/K))*K)
    if N % K >= K:
        ret = ret - K
    print(int(ret))

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

import math
 
if __name__ == "__main__":
    N, K = map(int, input().split())    
    ret =  N - N // K *K
    if ret > abs(ret-K):
        ret = abs(ret-K)
    print(int(ret))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
line1 = input().split()
n = int(line1[0])
k = int(line1[1])

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

line1 = input().split()
n = int(line1[0])
k = int(line1[1])
 
print(min(n % k, abs(n % k - k)))

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, K = map(int, input().split(' '))
if 2N < K:
    return N
else:
    a = N // K
    return min(abs(N - a * K), abs(N - a * (K + 1)))

N, K = map(int, input().split(' '))
if 2N < K:
    print(N)
else:
    a = N // K
    print(min(abs(N - a * K), abs(N - a * (K + 1))))

N, K = map(int, input().split(' '))
if 2 * N < K:
    return N
else:
    a = N // K
    mm = min(abs(N - a * K), abs(N - (a + 1) * K))
    return mm

N, K = map(int, input().split(' '))
if 2 * N < K:
    print(N)
else:
    a = N // K
    print(min(abs(N - a * K), abs(N - a * (K + 1))))

N, K = map(int, input().split(' '))
if 2 * N < K:
    print(N)
else:
    a = N // K
    mm = min(abs(N - a * K), abs(N - a * (K + 1)))
    print(mm)

N, K = map(int, input().split(' '))
if 2 * N < K:
    print(N)
else:
    a = N // K
    mm = min(abs(N - a * K), abs(N - (a + 1) * K))
    print(mm)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k = [int(_) for _ in input().split()]
base = n

print (n%k)

import sys
n,k = [int(_) for _ in input().split()]

amari = n % k
if amari == 0 :
  print("0")
  sys.exit()

base = amari
while base > abs(base - k):
  base = abs(base - k)

print(base)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,M = map(int, input().split())
def abc(n, m):
    if n<=abs(n-m):
        return n
    else:
        return abc(abs(n-m), m)
    p=abc(N,M)
print(p)

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)

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import sys
n,k = map(int,input().split())
a = abs(n-k)
if n < a:
    print(n)
    sys.exit()
while True:
    if n > a:
        a = abs(a-k)
    else:
        print(a)
        break

import sys
n,k = map(int,input().split())
l = []
a = abs(n-k)
b = abs(a-k)
if n < a:
    print(n)
    sys.exit()
else:
    for i in range(10**100):
        l.append(a)
        l.append(b)
        if l[i]<l[i+1]:
            print(l[i])

import sys
n,k = map(int,input().split())
a = abs(n-k)
if n < a:
    print(n)
    sys.exit()
while True:
    a = abs(a-k)
    if n < a:
        print(a)
        break
    else:
        continue

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


Verdicts: Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k=map(int,input().split())
if k>=n:
  print(min(k-n,n))
else:
  print(n-(n//k)*k)


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


Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
a, b = map(int, input().split())

m = (a - a%b) / b
print(min(a - m * b, (m + 1) * b -a))

a, b = map(int, input().split())

m = (a - a%b) / b
print(min(a%b, b - a%b))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
    half = k//2
    while c > half
        c = abs(c-k)
    l.append()
    print(min(l))

n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
    half = k//2
    while c > half:
        c = abs(c-k)
    l.append(c)
    print(min(l))

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
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()

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

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
i = [int(i) for i in input().split()]

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

print(n % k)

i = [int(i) for i in input().split()]
n = i[0]
k = i[1]
n2 = n % k
print(n2 if k > n2 else k % n2)

i = [int(x) for x in input().split()]
n = i[0]
k = i[1]

t = n % k
t2 = k -t

print(min(t, t2))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=map(int,input().split())

for i in range(10000000000000000000):
    value=N%K
    if value<K:
        break    
    N=abs(N-K)

print(value)

N,K=map(int,input().split())
temp=0
value=N%K
temp=abs(value-K)
if value>temp:
    value=temp   
print(value)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, K = int(input().split())

# N = 1000000000000000000
# K = 1
amari = N%K
bmari = abs(amari-K)
if amari >= bmari:
    print(bmari)
else:
    print(amari)

N, K = map(int, input().split())
a = N%K
b = abs(a - K)
print(min(a, b))

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=map(int,input().split())
print(N%K)

N,K=map(int,input().split())
print(min(N%K,K-N%K))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K = map(int, input().split())

result1 = N
result = abs(N - K)

if result1 < result:
  print(result1)
  
else:
  while result1 > result or result == 0:
    result1 = result
    result = abs(result - K)
    
  else:
    print(result)

N,K=map(int,input().split())
a=N%K
b=K/2
 
if a<=b:
    print(a)
else:
    print(K-a)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
def main():
    s = sum(a)
    thresh = s/4/m
    if a[m-1]>=thresh:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

def main():
    n,m = map(int,input().split())
    a = sorted(list(map(int,input().split())),reverse=True)     
    s = sum(a)
    thresh = s/4/m
    if a[m-1]>=thresh:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
def main():
    s = sum(a)
    thresh = s/4/m
    if a[m-1]<thresh:
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
def main():
    s = sum(a)
    thresh = s/4/m
    if a[m-1]<thresh:
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
def main():
  s = sum(a)
  thresh = s/4/m
  if a[m-1]>=thresh:
    print('Yes')
  else:
    print('No')

if __name__ == "__main__":
    main()

n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
def main():
    s = sum(a)
    thresh = s/4/m
    if a[m-1]>=thresh:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

n,k = map(int,input().split())
def main():
    m = n%k
    print(min(m,k-m))

if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, K = map(int, input().split())

if N == 0 or K == 1:
    N = 0
elif N == K:
    N = 0
elif N % K == 0:
    N = 0
else:
    N = N % K

print(N)

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

def act(int1, int2):
    return abs(int1-int2)

if N < K:
    pass
elif N == K:
    N = 0
elif N%K == 0:
    N = 0
else:
    while N >= K:
        N = act(N, K)

print(N)

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

if N == 0 or K == 1:
    N = 0
elif N == K:
    N = 0
elif N % K == 0:
    N = 0
else:
    N = N % K
    while N != 0:
        m = abs(N - K)
        if N < m:
            break
        else:
            N = m

print(N)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N, M = map(int, input().split())
print(abs(M-N))

n, k = map(int, input().split())
if n==0 or k==1:
    print(0)
    exit()
elif n<k:
    print(min(n, abs(n-k)))
    exit()
elif n % k == 0:
    print(0)
    exit()
else:
    mx = n%k
print(min(abs(mx-k), mx))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
in_ = input()
n, k = map(int, in_.split())

while True:
    n = n % k
    if n == 0:
        r = n
        break
    r = n - k
    if r < 0:
        if n > r:
            r = n
        break
    else:
        n = r
print(abs(r))


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

while True:
    if n < k:
        r = n
        break
    r = n - k
    if r < 0:
        break
    else:
        n = r
print(abs(r))


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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
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))

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

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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


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


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


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


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

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


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


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


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


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


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

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


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


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


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


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


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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = int(input()), int(input())
new = abs(N-K)
while(new<N):
    N = new 
    new = abs(new-K)
print(N)



N,K = int(input()), int(input())
new = abs(N-K)
while(new<N):
    N = new
    new = abs(new-K)
print(N)



N = int(input())
K = int(input())
n1 = N%K
n2 = K -n1
print(min(n1,n2))

#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = int(input()), int(input())
new = abs(N%K)
while(new<N):
    N = new
    new = abs(new%K)
print(N)



#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = N % K
n2 = K - new

print(min(new,n2))



Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import sys

n,k = map(int,input().split())
x = n+(n%k)
min = sys.maxsize

while True:
    if x%k == 0:
        min = 0
        break

    x = abs(x-k)
    if x == min :break
    elif x < min : min = x

print(min)



import sys

n,k = map(int,input().split())
x = k+(n%k)
min = sys.maxsize

while True:
    if x%k == 0:
        min = 0
        break

    x = abs(x-k)
    if x == min :break
    elif x < min : min = x

print(min)


Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
1000000000000000000 1

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

N = N % K

if K - N > N:
  print(N)
  exit()
print(K - N)

Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
# -*- coding:utf-8 -*-
import math

n, k = map(int, input().split())
while True:
    if n < k:
        break

    n = math.fabs(n-k)

print(int(n))

# -*- coding:utf-8 -*-
n, k = map(int, input().split())

print(n%k) if n%k < k-n%k else print(k-n%k)

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
NK = input().split()
N = int(NK[0])
K = int(NK[1]

def function(N,K):
    pre =N
    if N > K*10:
        return 0



    while(1):    
        # print('N',N)
        N = abs(N-K)
        if pre == N:
            return pre

        if pre< N:
            return pre
        pre = N 

print(function(N,K))




NK = input().split()
N = int(NK[0])
K = int(NK[1])

# N = 1000000000
# K = 1

def func(N,K):
    prev = N 

    while(1):
        N = abs(N-K)
        if prev<=N:
            return prev
        prev = N


def fun(N,K):
    N = (N % K) 
    return N  

S=fun(N,K)
T = func(S,K)
# print('S',S)
# print('T',T)
print(T)


Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
# input
N, K = map(int, input().split())

# process/output
if K == 1:
    print(0)
else:
    n = N
    while n > K:
        n = n//K + n % K

    p = n
    while True:
        t = abs(p-K)
        if t > p:
            break
        p = t
    print(p)



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

# process/output
if K == 1:
    print(0)
else:
    n = N
    if n > K:
        n = n%K

    p = n
    while True:
        t = abs(p-K)
        if t > p:
            break
        p = t
    print(p)


Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
n, k = [int(i) for i in input().split()]
for range(n):
	if abs(n - k) < n:
        n = abs(n-k)
print(n)


n, k = [int(i) for i in input().split()]
while true:
    if abs(n - k) < n:
        n = abs(n - k)
    else:
        break
print(n)


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

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

print(n)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
def sovle(x, y):
    while(x>=y):
        x=int(x-x/y*y)
    if(x>y-x):
        return y-x
    else:return x



if __name__ == '__main__':
    nums = list(map(int, input().split(" ")))
    print(sovle(nums[0], nums[1]))

def sovle(x, y):
    while(x>=y):
        x=x-x//y*y
    if(x>y-x):
        return y-x
    else:return x



if __name__ == '__main__':
    nums = list(map(int, input().split(" ")))
    print(sovle(nums[0], nums[1]))

Verdicts: Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
def abs(n, k):
    if n - k >= 0:
        return n-k
    else:
        return k-n
        
N, K = map(int, input().split())
while N > abs(N-K):
    N, K = abs(N-K), K
print(N)


N, K = map(int, input().split())
r = N % K
print(min(r, K-r))


Verdicts: Runtime Error

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import fractions
N,K = list(map(int,input().split()))
 
ans = fractions.gcd(N,K)
if N == 1 or K == 1:
  ans = 0
if N == ans or K == ans:
  ans = 0
print(ans)

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

ans = fractions.gcd(N,K)
print(ans)

import fractions
N,K = list(map(int,input().split()))
if N%K == 0 or K%N == 0:
  ans = 0
  print(ans)
else: 
  ans = fractions.gcd(N,K)
  if N == 1 or K == 1:
    ans = 0
  print(ans)

import fractions
N,K = list(map(int,input().split()))
 
ans = fractions.gcd(N,K)
if ans == 1:
  ans = 0
print(ans)

import fractions
N,K = list(map(int,input().split()))
 
ans = fractions.gcd(N,K)
if N == 1 or K == 1:
  ans = 0
print(ans)

N,K = list(map(int,input().split()))
ans = min(N%K,K-N%K)
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
N,K=input().split()
N,K=[int(N),int(K)]
 
minimum=N
while N < =minimum:
  N=abs(N-K)
  minimum=N
  
  
print(minimum)

N,K=input().split()
N,K=[int(N),int(K)]

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

N,K=input().split()
N,K=[int(N),int(K)]
 
minimum=10000000000000000000000
while N < minimum:
  N=abs(N-K)
  minimum=N
  
  
print(minimum)

N,K=input().split()
N,K=[int(N),int(K)]
 
minimum=0
while True:
  minimum=N
  if minimum > = N:
    minimum=N
  else:
    minimum=minimum
    break
  
  
print(minimum)

N,K=input().split()
N,K=[int(N),int(K)]

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

N,K=input().split()
N,K=[int(N),int(K)]

minimum=N%K
while N%K>K-N%K:
    minimum=K-N%K
    N=K-N%K
print(minimum)

Verdicts: Runtime Error

Time Limit Exceeded

Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
import sys

def main():
    n, k = [int(_) for _ in input().split()]
    
    m = abs(n - n // k * k)
    while True:
        ans = abs(m - k)
        if m <= ans:
            print(m)
            sys.exit()
main()

import sys

def main():
    n, k = [int(_) for _ in input().split()]
    
    m = abs(n - n // k * k)
    while True:
        ans = abs(m - k)
        if m <= ans:
            print(m)
            sys.exit()
        m = abs(m - k)
main()

Verdicts: Time Limit Exceeded

Accepted
Problem: Given any integer x, Aoki can do the operation below.  Operation: Replace x with the absolute difference of x and K.  You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Submission attempts (in order):
[n, k] = map(int, input().split())
 
n -= n//k
if n > k//2:
  n = k -n
print(n)
  
  
  


[n, k] = map(int, input().split())
 
n -= (n//k) * k
if n > k//2:
  n = k -n
print(n)


Verdicts: Wrong Answer

Accepted