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):
n, k = map(int, input().split())

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

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

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

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

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

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

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



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

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

Verdicts: 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=map(int,input().split()
#n=7
#k=4

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

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



n,k=map(int,input().split())
#n=7
#k=4

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

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


n,k=input().split()


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

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


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

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

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


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

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

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


Verdicts: Runtime Error

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):
N,K = map(int,input().split())

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

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

print(min(N % K,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):
import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
min = N
for i in range(10**6):
    N = abs(N-K)
    if min > N:
        min = N
    if N == 0:
        min = 0
        break
print(min)

import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
for i in range(10*9):
    N = abs(N-K)
    if N == 0:
        break
print(N)

from collections import deque
k = int(input())
Q = deque(range(1, 10))
for _ in range(k):
  x = Q.popleft()
  y = x % 10
  z = 10*x + y
  if y != 0:
    Q += [z-1]
  Q += [z]
  if y != 9:
    Q += [z+1]
print(x)

import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
min = N
for i in range(10**8):
    N = abs(N-K)
    if min > N:
        min = N
    if N == 0:
        min = 0
        break
print(min)

import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
min = N
for i in range(10*18):
    N = abs(N-K)
    if min > N:
        min = N
    if N == 0:
        min = 0
        break
print(min)

import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
min = N
for i in range(10**7):
    N = abs(N-K)
    if min > N:
        min = N
    if N == 0:
        min = 0
        break
print(min)

import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
for i in range(10*18):
    N = abs(N-K)
    if N == 0:
        break
print(N)

import fractions
N, K = map(int,input().split())
N = fractions.gcd(N,K)
for i in range(10*6):
    N = abs(N-K)
    if N == 0:
        break
print(N)

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

#main
t = N % K
ans = min(t, K - t)

#output
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Time Limit Exceeded

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 = map(int, input().split())
ans = n % k
print(ans)

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

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

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())
x = n
i = 0
if min(n, k) == 1:
    print("0")
else:
    while i < n:
        x = abs(x - k)
        i += 1
        print(min(n, x))


n, k = map(int, input().split())
x = n
i = 0
if k == 1:
    print("0")
else:
    while i < n:
        x = abs(x - k)
        i += 1
        print(min(n, x))


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

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)

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

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

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

Verdicts: 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):
N,K = map(int,input().split(' '))
ans_list = [N]
for i in range(N//K+1):
    ans = abs(N-K)
    ans_list.append(ans)
    
print(min(ans_list))

N,K = map(int,input().split(' '))
first = N - (K*(N//K))
second = abs(first - K)
final = [first,second,K]
print(min(final))

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 >= 1.0:
    amari = n%k
else:
    amari = n

if abs(amari-k) < amari:
    print(abs(amari-k))
print(amari)

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

amari = n%k

if abs(amari-k) < amari:
    print(abs(amari-k))
else:
  print(amari)

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):
data = input().split()
n = int(data[0])
k = int(data[1])

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

print(res)


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

print(res)

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 = list(map(int, input().split()))
a = N // K
b = N % K

print(min(abs(N - K * a), abs(b)))

X, N = map(int, input().split())
p = list(map(int, input().split()))

for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break

N, K = list(map(int, input().split()))
a = N // K
b = N % K
print(min(abs(N - K * a), abs(b - 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())
i=1
A[0]=N
if K!=1:
    while True:
        A[i]=abs(A[i]-K)
        if A[i] in A:
            break
        i+=1
    print(min(A))
else:
    print(0)

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

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(float,input().split())
t = k
if n%k==0:
    print(0)
else:
    while(n%10==0 and str(n)[-1] == "0"):
        n=n//10
    while(n%2==0 and k%2==0):
        n=n//2
        k=k//2
    while(n%3==0 and k%3==0):
        n=n//3
        k=k//3
    while(n > abs(n-k)):
        n=abs(n-k)
    print(n)

n,k = map(int,input().split())
ans = min(n%k,k-(n%k))
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())
while True:
  if abs(N)>abs(N-K):
    N-=K
  else:
    print(N)
    exit()

n, k = map(int, input().split())
ans1 = n%k
ans2 = -(ans1-k)

print(min(ans1, ans2))


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())
cnt = (N // K)

if N == K:
    print(0)
elif N < K:
    print(N)
elif N > K:
    if N % K == 0:
        print(cnt*K - N)
    else:
        if (cnt*K - N) > ((cnt+1)*K - N):
            cnt += 1
            print(abs(cnt*K - N))
        else:
            print(abs(cnt*K - N))

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

if N == K:
    print(0)
elif N < K:
    print(N)
elif N > K:
    cnt = (N // K)
    print(cnt*K - N)


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

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

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

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

a = N % K
if a == 0:
    print(0)
else:
    print(min(a, abs(a-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):
array = list(map(int, input().split()))
tmp = array[0]
array[0] = abs(array[0] - array[1])
while (tmp == array[0]):
  tmp = array[0]
  array[0] = abs(array[0] - array[1])

print(array[0])


array = list(map(int, input().split()))
tmp = array[0] % array[1]
array[0] = array[0] / array[1]
while (tmp >= array[0]):
  tmp = array[0] % array[1]
  array[0] = array[0] / array[1]
print(tmp)


array = list(map(int, input().split()))
tmp = array[0] % array[1]
print(tmp)

array = list(map(int, input().split()))
tmp = array[0] % array[1]
if (tmp <= array[1] / 2):
  print(tmp)
else:
  print(abs(tmp-array[1]))


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

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

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

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

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

while  N > M:
  x = N - M
  x = abs(x)
  N = x
  
print(N)

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

t = N % K
t2 = K - t

if t > t2:
  print(t2)
else:
  print(t)

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

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

n = int(input())
k = int(input())
if n >= k:
  n = n % k

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

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

if n >= k:
  n %= k
  
print(min(n, -(n-k)))

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):
n,k = map(int, input().split())

shou,lis = n//k,[]
if shou!=0: n=n%(shou*k)
for i in range(10):
  n=abs(n-k)
  lis.append(n)
print(lis)

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

shou,lis = n//k,[]
if shou!=0: n=n%(shou*k)
for i in range(10):
  n=abs(n-k)
  lis.append(n)
print(min(lis))

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

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

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

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

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):
data = input().split()
n,k = int(data[0]),int(data[1])

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

data = input().split()
n,k = int(data[0]),int(data[1])
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())
ans1 = N % K
ans2 = abs(ans1 - K )
print(min(ans1,ans2)

N,K = map(int,input().split())
ans1 = N - K
ans2 = abs(ans1 - K)
print(min(ans1,ans2)

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

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):
n,k=(int(i) for i in input().split())
print(n%k)

n,k=(int(i) for i in input().split())
print(min(n%k,(((n//k)+1)*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())
ans=10e20
if n%k==0:
    ans=0
else:
    while ans>=n:
        ans=abs(n-k)
        n=abs(n-k)
print(ans)

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

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):
import sys
n, k = list(map(int, input().split()))

if (k == 1):
    print(0)
    sys.exit()

s, a = divmod(n, k)

ans = 0
if (a == 0):
    ans = s
else:
    ans = a

print(ans)


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

if (k == 1):
    print(0)
    sys.exit()

ans = 0
v_ans = 0
if (n > k):
    v_ans = n % k
else:
    v_ans = n

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

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

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

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=[int(s) for s in input().split()]
print(a%b)

a,b=[int(s) for s in input().split()]
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())

print(N,K)    

x = N

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

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

a = N%K

print(min(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):
from ctypes import c_longlong as ll

n = ll(input(""))
m = ll(input(""))
n= n % m
print(min(n, m-n))

import numpy

n, m = input().split()
n = numpy.int64(n)
m = numpy.int64(m)
n = n % m
print(min(n, m-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):
K, N = map(int,input().split())
a = list(map(int,input().split()))
x = [a[0]-a[-1]+K]
for i in range(1,N):
    x.append(a[i]-a[i-1])
print(x)
print(K-max(x))

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

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*(n // k))
else :
    print(n)

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

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

if k-n > n:
    print(n)
else:
    print(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):
import math
N,K = list(map(int, input().split()))


i=math.modf(N/K)[1]

N_i=N-K*i
N_i_p1=N_i-K
 
if abs(N_i_p1)>N_i:
  print(N_i)
if abs(N_i_p1)<N_i:
  print(abs(N_i_p1))
if abs(N_i_p1)==N_i:
  print(N_i)

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

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


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

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

N,K = map(int,input().split())
if N > K:
    print(N % K)
elif N < K:
    ans = min(N,K-N)
    print(ans)
elif N == K:
    print(0)

N,K = map(int,input().split())
if N > K:
    print(N % K)
elif N < K:
    ans = min(N,K-N)
    print(ans)
if N == K:
    print(0)

N,K = map(int,input().split())
if N > K:
    a = N % K
    ans = min(a,K-a)
    print(ans)
elif N < K:
    ans = min(N,K-N)
    print(ans)
elif N == K:
    print(0)

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())
while n>=0:
  n=abs(n-k)
  if n-k<=0:
    print(n)
    break

n,k=map(int,input().split())
while n>=0:
  n=abs(n-k)
  if n-k<=0:
    print(abs(n-k)
    break

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

n,k=map(int,input().split())
while n>=0:
  n=abs(n-k)
  if n-k<=0:
    print(abs(n-1))
    break

n,k=map(int,input().split())
while n>=0:
  if n-k<=0:
    print(max(abs(n-k),n)
    break
  n=n-k

n,k=map(int,input().split())
while n>=0:
  if n-k<=0:
    print(max(abs(n-k),n))
    break
  n=n-k

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

n,k=map(int,input().split())
while n>=0:
  n=ans(n-k)
  if n-k<=0:
    print(n)
    break

n,k=map(int,input().split())
while n>=0:
  n=ans(n-k)
  if n-k<=0:
    print(n)

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

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

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

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>K:
  y = int(N/K)
  x = N - y*K
else:
  x = N 
#print(x)
cnt = 0
ans = x
while cnt<10:
  x = abs(x-K)
  ans = min(ans, x)
  cnt += 1
ans = min(ans, 0)
print(ans)

N,K=map(int, input().split()) 
y = int(N//K)
x = N - y*K
ans = min(x, abs(x-K))
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 = input().split()
n=int(n)
k=int(k)
if n % k > (n % k) - k:
    print(n % k)
else:
    print(k - (n % k))

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

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

# def pow(x, n):
#   ans = 1
#   while(n > 0):
#     if(bin(n & 1) == bin(1)):

#     x = x*x

#   return ans
#


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)


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)


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 = list(map(int, input().split()))
# print(n, k)


min_result = n
flag = 0
dic = {}

z = n // k
zz = n //z
result = zz

while flag==0:
    result = abs(result - k) 
    print('result',result)
    print('min_result',min_result)
    if result <= min_result:
        min_result = result
        dic[result] = dic.get(result, 0) + 1

        if dic[result] > 1:
            flag=1
print(min_result)

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


x = n % k
y = k - x

if x > y:
    print(y)
    
else:
    print(x)

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,m = map(int, input().split(' '))
re = 0
if n > m:
    while re >= 0:
        re = n - m
        n = m
        m = re
else: 
    print(n)

N,K = map(int, input().split())
N = N%K
absolute = abs(K-N)
print(absolute if absolute < N else 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):
import sys
input = sys.stdin.readline

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


#     print(0)
# else:
ans = n % k
print(ans)

import sys
input = sys.stdin.readline

n, k = map(int, input().split()) 
n = n % k
d = set([n])
while True:
    diff = abs(n - k)
    pre = n
    n = min(diff, n)
    if n in d:
        break
    else:
        d.add(n)
print(min(d))

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

n,k = map(int,input().split())
print(min(n%k,(k-(n%k))%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):
list1=[]
a,b=map(int,input().split())
d=a
e=a
if a%b==0:
    print(0)
else:
    for i in range(d):
        a=abs(a-b)
        list1.append(a)
        if e<a:
            list2= sorted(list1, reverse=True)
            print(list2[-1])
            break

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

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 main():
  n, k = map(int, input().rstrip().split())
  
  if n % k <= k / 2:
	print(n % k)
  else:
    print(k - (n % k))


if __name__ == '__main__':
    main()


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


if __name__ == '__main__':
  main()


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):
list = input().split(" ")

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

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

result = mod if mod <= standardNum else minusMod

print(result)

list = input().split(" ")

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

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

result = mod if mod <= minusMod else minusMod

print(result)

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

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

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

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


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

c=abs(n-k)
d=abs(c-k)
if(c+d==k):
    if(c>d):
        print(d)
    else:
        print(c)
    exit()
if(n>=k):
    if(n%k==0):
        print(0)
        exit()
    else:
        a=n-k*(n//k)
        b=k*(n//k+1)-n
        if(a>b):
            print(b)
        else:
            print(a)
        exit()
else:
    
    while(1):
        a=abs(n-k)
        if(n>a):
            n=a
        else:
            print(n)
            exit()


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):
from fractions import gcd

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

if n == 1 or k == 1:
    print(0)
else:2 6
    print(gcd(n,k))

from fractions import gcd

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

if n == 1 or k == 1:
    print(0)
else:
    print(gcd(n,k))

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

if n==0:
    print(0)
else:
    while result > abs(result-k):
        result=abs(result-k)
    print(result)

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):
a = int(input())
b = int(input())
c = abs(a - b)
d = abs(c-b)
print(d)

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 = list(map(int, input().split()))
print(n%k)

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

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

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

print(ans)

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())
ans = 100000
for i in range(1000000):
    k = abs(N-K)
    if ans > k:
        N = k
        ans = k
if N != 1 and K != 1:
    print(ans)
else:
    print(0)

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

if K == 1:
    print(0)
    exit()
else:
    for i in range(100000000):
        k = abs(N-K)
        if k < N:
            N = k                
print(N)

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

if K == 1:
    print(0)
    exit()
elif N == 0:
    print(0)
    exit()    
else:
    a = N-K*(N//K)
    b =abs(N-K*(N//K +1))
    print(min(a,b))

Verdicts: Wrong Answer

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):
val= input()
val_list=list(map(int,val.split()))
n=val_list[0]
k=val_list[1]
while True:
    n = abs(n-k)
    if n< k:
        break
print(n)

val= input()
val_list=list(map(int,val.split()))
n=val_list[0]
k=val_list[1]
n= n % k
judge=[]
while True:
    n = abs(n-k)
    if n in judge:
        break
    else:
        judge.append(n)
min= judge[0]
for i in range(0,len(judge)):
    if min > judge[i]:
       min= judge[i]

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):
import numpy as np


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

i =N
while i>0:
    i = i-K
    i_ = i 
print (i if i<np.abs(i_) else np.abs(i_))

import numpy as np


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

time = N // K
min_ = N- time*K
min = N- (time+1)*K
print (min_ if min_<np.abs(min) else np.abs(min))

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 n >= k:
  n = n-k
print(n)

n,k = map(int, input().split())
print(min(n%k, abs(n%k-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 = list(map(int, input().split()))

print(N % K)


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

print(min(N % K, abs(N % (-1 * 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())
ans=0
n%=m
ans=(min(n,(k-n))
print(ans)


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


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


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

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

aa = int(N/K)
ans = N - K*aa
ans_2 = ans - K

if(N<K):
  print(N)
elif(N%K == 0):
  print("0")
elif(ans<ans_2)
  print(ans)
else:
  print(ans_2)


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


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

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):
num = list(map(int, input().split()))

loop = [0]

for i in loop:
  if num[0] < num[1]:
    difference = abs(num[0] - num[1])
    if difference > num[0]
      break
    else:
      num[0] = difference
  elif num[1] == 1:
    num[0] = 0
    break
  elif num[1] == 0:
    break
  num[0] = abs(num[0] - num[1])
  loop.append(i+1)

print(num[0])

num = list(map(int, input().split()))

loop = [0]

for i in loop:
  if num[0] < num[1]:
    difference = abs(num[0] - num[1])
    if difference > num[0]:
      break
    else:
      num[0] = difference
      break
  elif num[1] == 1:
    num[0] = 0
    break
  elif num[1] == 0:
    break
  if i = 0:
    num[0] = num[0] % num[1]
  num[0] = abs(num[0] - num[1])
  loop.append(i+1)

print(num[0])

num = list(map(int, input().split()))

loop = [0]

for i in loop:
  if num[0] < num[1]:
    difference = abs(num[0] - num[1])
    if difference > num[0]:
      break
    else:
      num[0] = difference
      break
  elif num[1] == 1:
    num[0] = 0
    break
  elif num[1] == 0:
    break
  if i == 0:
    num[0] = num[0] % num[1]
  num[0] = abs(num[0] - num[1])
  loop.append(i+1)

print(num[0])

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):
n,m=map(int,input().split())
a=list(map(int,input().split()))
suma=sum(a)
l=suma/(4*m)
a.sort(reverse=True)
if a[m-1]>=l:
    print('Yes')
else:
    print('No')


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

n,k=map(int,input().split())
print(min(n%k,k-n%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())
print(min(abs(n%k),k-abs(n%k))

n,k = map(int,input().split())
print(min(n%k,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):
# ABC161_C
from fractions import gcd
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()
ans=0
ans=gcd(n,k)

print(ans)

# ABC161_C
from fractions import gcd
n,k=map(int,input().split())
# if k==1:
#     print(0)
#     exit()

t=n
# while n>abs(n-k):
# while t>0 and abs(t-k)>0:
while t>abs(t-k) and abs(t-k)>0:
    t=t%abs(t-k)
    if n==t:
        break
if t==k:
    t=0
print(t)
# ans=0
# ans=gcd(n,k)

# print(ans)
# ans=0
# # a=abs(n-k)
# ans=n%a
# print(ans)
# a=abs(n-k)
# # t=0
# while n>a:
#     n=n%a
# print(n)




# ABC161_C
from fractions import gcd
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()


while n>abs(n-k):
    n=abs(n-k)
if n==k:
    n=0
print(n)
# ans=0
# ans=gcd(n,k)

# print(ans)
# ans=0
# # a=abs(n-k)
# ans=n%a
# print(ans)
# a=abs(n-k)
# # t=0
# while n>a:
#     n=n%a
# print(n)




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

Verdicts: Wrong Answer

Wrong Answer

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 = int(input())
K = int(input())
S = N // K
Answer = abs(N - K*S)
if abs(Answer - K) <= Answer:
    Answer = abs(Answer - K)
print(Answer)

N,K = map(int,input().split())
S = N // K
Answer = abs(N - K*S)
if abs(Answer - K) <= Answer:
    Answer = abs(Answer - K)
print(Answer)

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
from fractions import gcd


def input():
    return sys.stdin.readline().strip()


N, k = map(int, input().split())
a = gcd(N, k)
if k == 1:
    print(0)
else:

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


import sys


def input():
    return sys.stdin.readline().strip()


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


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


def main(n: int, k: int):
    m = min(n, n % k)

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


if __name__ == "__main__":
    n, k = map(int, input().split())
    main(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):
print(0)

N,K = map(int, input().split(' '))
x = N % K
x1 = K - x
if x > x1:
  print(x1)
else:
  print(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())
min(N%K,K-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):
str = input().split()
n = int(str[0])
k = int(str[1])
t = n%k
other = abs(k-t)
print(min(t,other))
if t <= other:
    print(t)
else:
    print(other)

str = input().split()
a1 = int(str[0])
a2 = int(str[1])
if a1 >= a2:
    a1 = a2%a1
if a1 < a2-a1:
    print(a1)
else:
    print(a2-a1)

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

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 abs(n-k)>n:
  while True:
    n -= k
    if n<0:
      break
      
print(abs(n))
  

n,k = map(int,input().split())
num = 0
while True:
	num = n-k
    if num < 0:
      print(abs(num))

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


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


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

d = n//k

n = n - d*n

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


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

if n>k:
  n = n%k

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

print(ans)

Verdicts: Wrong Answer

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):
from fractions import gcd
n,k=map(int,input().split())
if k==1:
    print(0)
else:
    print(gcd(n,k))


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


Verdicts: Wrong Answer

Accepted