Problem:


Score : 300 points

Problem Statement

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.

Constraints

0 ≤ N ≤ 10^{18}

1 ≤ K ≤ 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the minimum possible value taken by N after Aoki does the operation zero or more times.

Sample Input 1

7 4

Sample Output 1

1

Initially, N=7.

After one operation, N becomes |7-4| = 3.

After two operations, N becomes |3-4| = 1, which is the minimum value taken by N.

Sample Input 2

2 6

Sample Output 2

2

N=2 after zero operations is the minimum.

Sample Input 3

1000000000000000000 1

Sample Output 3

0



Sample input:
7 4


Sample output:
1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split(' ')]

def res():
  if N == K:
    return 0
  elif N > K:
    return N % K
  else :
    return N

print(res())

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]

N_1 = N % K
N_2 = K - N_1

if N_1 == 0:
    print(N_2)
else:
    print(min(N_1, N_2))

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split(' ')]

min = 0
prev = 0

while abs(N - K) > min:
  min = abs(N - K)
  N = abs(N - K)
  prev = min


print(min)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split(' ')]

min = 0
prev = 0

while abs(N - K) > min:
  min = abs(N - K)
  N = min

print(N - K)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split(' ')]

min = 0
prev = 0

while abs(N - K) > N:
  min = abs(N - K)
  N = min


print(min)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split(" ")))
while True:
    a = abs(n-k)
    if n <= a:
        break
    else:
        n = a

Submission status: Wrong Answer

Solution code:
list_input = [int(n) for n in input().split()]

N = list_input[0]
K = list_input[1]

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
N,K=list(map(int,(stdin.readline().strip().split())))
print(gcd(N,K))

Submission status: Wrong Answer

Solution code:
inn = input()

x, y = inn.split(' ')

x = int(x)
y = int(y)

if y > x:
  tmp = x
  x = y
  y = tmp

minn = 1e9
  
while True:
  x = abs(x - y)
  tmp = x
  x = y
  y = tmp
  
  if y >= minn:
    break
   
  minn = min(y, minn)
  
print(minn)

Submission status: Wrong Answer

Solution code:
inn = input()

x, y = inn.split(' ')

x = int(x)
y = int(y)

if y > x:
  tmp = x
  x = y
  y = tmp

minn = 1e9
  
while True:
  x = abs(x - y)
  tmp = x
  x = y
  tmp = x
  
  if y >= minn:
    break
   
  minn = min(y, minn)
  
print(minn)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
if N<K:
    print(N)
else:
    A=N%K
    ans=min(A,K-A)
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
if N<=K:
    print(N)
else:
    A=N%K
    ans=min(A,K-A)
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

while True:
  buff -= k
  if n <= 0 or buff < n:
    n = abs(n)
    break
  n = buff

print(n)

Submission status: Wrong Answer

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

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

print(n)

Submission status: Wrong Answer

Solution code:
n = [int(e) for e in input().split(" ")]
if(n[0] == n[1] or n[1] == 1):
    print("0")
elif(n[0] > n[1]):
    print(n[1] - (n[0] % n[1]))
else:
    print(n[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
num=list(map(int, input().split()))
ans=1000
count=0
value=num[0]
value1=num[1]
if num[0]<=num[1]:
  if num[0]<=num[1]-num[0]:
    ans=num[0]
  else:
    ans=num[1]-num[0]
else:
  while value-num[1]>=0:
    value=value-num[1]
    count=count+1
    for i in range(count*2):
      value1=abs(value1-num[1])
      if ans>value1:
        ans=value1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#c
n,k = map(int,input().split())
if n>=k:
    if n-k>n%k:
        print(n%k)
    else:
        print(n-k)
else:
    if n<(k-n):
        print(n)
    else:
        print(k-n)

Submission status: Wrong Answer

Solution code:
#c
n,k = map(int,input().split())
if n>=k:
    print(n%k)
else:
    if n<(k-n):
        print(n)
    else:
        print(k-n)

Submission status: Wrong Answer

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

if n < k and k - n <= k/2:
  n = k - n
  if n > min:
    n = min

print(min)
# 7 3 1 =2

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

s = n % m

plus = n - m * s
minus = n - m * (s+1)

minus = abs(minus)

print(min(plus, minus))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
list_NK = list(map(int, input().split())) 
N = list_NK[0]
K = list_NK[1]
abs_now  = N
while all:
    abs_past = abs(abs_now - K)
    if(abs_past >= abs_now):
        break
    abs_now = abs_past
print(abs_past)

Submission status: Wrong Answer

Solution code:
list_NK = list(map(int, input().split())) 
N = list_NK[0]
K = list_NK[1]
i = 0
abs_list = []
abs_list.append(N)
while all:
    abs_list.append(abs(abs_list[i] - K))    
    if(abs_list[i+1]>=abs_list[i]):
        break
    i += 1
print(abs_list[len(abs_list)-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if N == K:
  print(0)
elif N < K:
  print(N)
elif N > K:
  tmp = N%K
  a = K-tmp
  b = tmp
  if a < b:
    print(a)
  elif a > b:
    print(b)
  else:
    print(a)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if N == K:
  print(0)
elif N < K:
  print(N)
elif N > K:
  tmp = N%K
  a = K-tmp
  b = tmp
  if a < b:
    print(a)
  else:
    print(b)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if N == K:
  print(0)
elif N < K:
  print(N)
elif N > K:
  tmp = N%K
  a = K-tmp
  b = tmp
  if a < b:
    print(a)
  elif a > b:
    print(b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
temp = n
while temp < abs(temp - k):
    temp = abs(temp - k)

print(temp)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
mod = N % K
print(mod, abs(K - mod))

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__': 
    n, k = [int(i) for i in input().split(" ")]
    while abs(n - k) < n:
        if k == 1:
            n = 0
        if n%k==0:
            n = int(n/k)
        else:
            n = abs(n - k)
    print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = []
ans = 1
if(n%m == 0):
  ans=0
else:
  for x in (0,n):
    n = abs(n-m)
    l.append(n)
  l.sort()
  ans = l[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = []
ans = 1
if(n%m == 0):
  ans=0
else:
  n = n-m
  l.append(n)
  
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    a, b = map(int, input().split())
    save_result = set()
    save_result.add(a)
    while True:
        a = a - b
        if a == 0:
            print(a)
            break
        if a < 0:
            abs_s = abs(a)
            save_result.add(abs_s)
            break
        else:
            save_result.add(a)

    print(min(list(save_result)))


resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
a = int(N / K)
print(int(min(abs(N - K*a), abs(N - K*(a+1)))))

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
x = n//k
if(n<k and n!=0):
    x = k//n
    print(min(abs(k*x-n),abs(k*(x+1)-n)))
else:
    print(min(abs(k*x-n),abs(k*(x+1)-n)))

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
x = math.ceil(n/k)
if(n<k):
    print(min(n,abs(n-k)))
else:
    print(abs(k*x-n))

Submission status: Wrong Answer

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

print(n % k)

Submission status: Wrong Answer

Solution code:
#スペース区切りの整数の入力
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(abs(ans_2))

Submission status: Wrong Answer

Solution code:
main, sub = input().split()
main = int(main)
sub = int(sub)
if sub >= main:
    print("0")
else:
    for i in range(main-2,main+2):
        if i % sub == 0:
            print(abs(i-main))
            break

Submission status: Wrong Answer

Solution code:
x, K = map(int, input().split())
while float(x - K) >= 0:
	x = x - (x // K) * K
print(x)

Submission status: Wrong Answer

Solution code:
x, K = map(int, input().split())
while float(x - K) >= 0:
	x = x - K
print(x)

Submission status: Wrong Answer

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

if N % K == 0:
    print(0)
elif N > K*2:
    print(N)
else:
    A = K % N
    print(min(abs(N-A), abs(N-A*2)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

x = N % K
print(K - x if x != N else x)

Submission status: Wrong Answer

Solution code:
main, sub = input().split()
main = int(main)
sub = int(sub)
for i in range(main-2,main+2):
    if i % sub == 0:
        print(abs(i-main))
        break

Submission status: Wrong Answer

Solution code:
N, K = (int(x) for x in input().split(' '))
tmp = N % K

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

Submission status: Wrong Answer

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

if n == 0:
    result = k
elif n % k == 0:
    result = 0
else:
    result = n
    while abs(result - k) < result:
        result = abs(result - k)

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
i = [int(i) for i in input().split()]

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

print(n % k)

Submission status: Wrong Answer

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

print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
if 2 * n <= k:
    print(n)
else:
    print(abs(n % k - k))

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
ans = 0
if n < k:
    ans = n
else:
    ans = min(n%k,k-n%k)

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
ans = 0
if n < k:
    ans = n
else:
    ans = min(n%k,abs(n%k-k))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math as mh
N,K=map(int,input().split())
count=True

N=mh.sqrt((N-K)**2)
while count:
    
    if N<mh.sqrt((N-K)**2):
        count=False
    else :
        N=mh.sqrt((N-K)**2)
        

print(int(N))

Submission status: Wrong Answer

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

n = N % K

if n != 0 and N > K:
    n = K % n

print(n)

Submission status: Wrong Answer

Solution code:
from math import ceil
n,m=map(int,input().split())
a,b=n,m
z=abs(n-m)
if n>m:
    n = n-(ceil((n-m)/m))*m
 
print(min(min(n,m-n),z))

Submission status: Wrong Answer

Solution code:
from math import ceil
n,m=map(int,input().split())
a,b=n,m
if n>m:
    n = n-(ceil((n-m)/m))*m
 
print(min(n,m-n))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from math import ceil
n,m=map(int,input().split())
a,b=n,m
if n>m:
    n = n-(ceil((n-m)/m))*m

print(min(n,m-n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
print(N%K)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
l=N%K
print(min(l,N-K))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
l=abs(N//K)
p=K*l
for i in range(1,10000):
	if abs(N-(K*(l+i)))<abs(N-p):
		p+=i
print(abs(N-p))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
l=abs(N//K)
p=K*l
for i in range(1,10000):
	if abs(N-(K*(l+i)))<abs(N-p):
		p=p+1
print(abs(N-p))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = list(map(int,input().split()))
tmp = np.zeros(2)
tmp[0] = N % K
tmp[1] = abs(tmp[0] - K)
#tmp[1] = -N % K
print(int(tmp.min()))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
if N >= K:
	print(min([N, N%K, abs(K-N%K)]))
else:
	print(min([N, N%K]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
print(min([N, N%K] + (K < N)*[N-N%K]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
	if(b==0):
		return a
	return gcd(b,a%b)

n, k = [int(x) for x in input().split()]
print(min(gcd(n,k),k-gcd(n,k)))

Submission status: Wrong Answer

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

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

print(result)

Submission status: Wrong Answer

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

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

print(result)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int, input().split())

ans1 = abs(N - (K * math.floor(N / K)))# 余り
ans2 = abs(N - (K * (math.floor(N / K)+1)))# 余り

print(min(ans1,ans2))

Submission status: Wrong Answer

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

ans1 = abs(N - (K * int(N / K)))
ans2 = abs(N - (K * (int(N / K)+1)))

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]

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

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]

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

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]


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

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]


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

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]


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

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]


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

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]


i = n - x * int(n/x)
l.append(abs(i-x))
l.append(abs(l[0]-x))
print(min(l))

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]


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

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]

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

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=[]

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

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]


n = n - x * int(n/x)
l.append(abs(n-x))
l.append(abs(l[0]-x))
print(min(l))

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]

if(x!=1 and n!=0):
  n = n - x * int(n/x)
  l.append(abs(n-x))
  l.append(abs(l[0]-x))
  print(min(l))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]

if(x!=1 and n!=0):
  n = n - x * int(n/x)
  l.append(abs(n-x))
  l.append(abs(l[0]-x))
  print(min(l))
elif(n == 0):
  print(0)
elif(x == 1):
  print(0)

Submission status: Wrong Answer

Solution code:
import math
n_and_k = list(map(int, input().split()))

n = n_and_k[0]
k = n_and_k[1]
quotient = n // k
remainder = n % k
if n==k:
    print(0)
elif n > k:
    print(min([quotient, remainder]))   
else:
    print(max([quotient, remainder]))

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]

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

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
l=[]

if(x!=1):
  l.append(abs(n-x))
  l.append(abs(l[0]-x))
  print(min(l))
elif(x == 1):
  print(0)

Submission status: Wrong Answer

Solution code:
import math
n_and_k = list(map(int, input().split()))

n = n_and_k[0]
k = n_and_k[1]
quotient = n // k
remainder = n % k
if n > k:
    print(min([quotient, remainder]))   
else:
    print(max([quotient, remainder]))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
print(a)
if a[0]<a[1]:
  print(min(a[0],a[1]-a[0]))
else:
  r=a[0]%a[1]
  print(min(r,a[1]-r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n < abs(n-k):
  print(n)
  exit()

n = abs(n-k) % k

if n == 0:
  print(n)
  exit()

print(abs(n-k))

Submission status: Wrong Answer

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

if n < abs(n-k) % k:
  print(n)
  exit()

n = abs(n-k) % k

if n == 0:
  print(n)
  exit()

print(abs(n-k))

Submission status: Wrong Answer

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

if n == 0:
  print(n)
  exit()

print(abs(n-k))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
x = n % k
print(min(x, x-k))

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
x = n % k
print(max(x, x-k))

Submission status: Wrong Answer

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

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

print(_min)

Submission status: Wrong Answer

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

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

print(_min)

Submission status: Wrong Answer

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

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

print(_min)

Submission status: Wrong Answer

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

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

print(_min)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a,b = n,k
while b>0:
    a,b = b,a%b

if k==a:
    print(0)
else:
    print(a)

Submission status: Wrong Answer

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

a = n % k

while a > abs(a-k):
    print(a, "-" , k, "=" , abs(a-k))
    a = abs(a-k)
    
print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = list(map(int,input().split()))
tmp = np.zeros(2)
tmp[0] = N % K
tmp[1] = abs(tmp[0] - K)
if tmp[0] < tmp[1]:
    ans = tmp[0]
else:
    ans = tmp[1]
print(int(ans))
#print(int(tmp.min()))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = list(map(int,input().split()))
tmp = np.zeros(2)
tmp[0] = N % K
tmp[1] = abs(tmp[0] - K)

print(int(tmp.min()))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = list(map(int,input().split()))
if N == 0:
    print(K)
else:
    tmp = np.zeros(2)
    tmp[0] = N % K
    tmp[1] = abs(tmp[0] - K)
    print(int(tmp.min()))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = list(map(int,input().split()))
tmp = np.zeros(2)
tmp[0] = N % K
tmp[1] = abs(tmp[0] - K)
print(int(tmp.min()))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def main():

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

    if n <k:
        print(n)
        sys.exit(0)
    if n % k == 0:
        print(0)
        sys.exit(0)
    
    print(min(abs(n%k-k),n%k))


main()

Submission status: Wrong Answer

Solution code:

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


abs_value = abs(N - K)

if abs_value ==0:
    print (0)
    exit (0)


value = N//abs_value
value2 = N%K

if value==0:
    print (N)
elif value2==0:
    print(0)
else:
    print (N - abs_value * value)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

if k > n:
    print(n)
    exit(0)

a = n % k
b = (a - k) * -1

if a == 0:
    print(a)
else:
    if a > b:
        print(b)
    else:
        print(a)

Submission status: Wrong Answer

Solution code:
#n=int(input())
n,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
ans=0
import fractions
newval=n%k
if n>=k:
    ans=min(n%k,abs(k-n%k))
else:
    ans=n
print(ans)

Submission status: Wrong Answer

Solution code:
#n=int(input())
n,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
ans=0
import fractions
newval=n%k
if n>=k:
    ans=min(n%k,k-n%k)
else:
    ans=n
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
if n > k:
  if n%k != 0:
    ans = abs((n%k) - k)
  else:
    ans = 0
else:
  ans = n
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
ans = 0
if n > k:
  if n%k != 0:
    ans = abs((n%k) - k)
else:
  ans = n
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
ans = 0
if n%k != 0 and n>k:
  ans = abs((n%k) - k)
else:
  ans = n
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- 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))

Submission status: Wrong Answer

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

if n<k:
    print(n)
    exit()
else:
    minV = (n%k) if (n%k) < (k-n%k) else (k-n%k)
    print(minV)

Submission status: Wrong Answer

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

if n<k:
    print(n)
    exit()
else:
    minV = n%k if n%k < k-n%k else k-n%k
    print(minV)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n < k:
    print(n)
    exit()

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

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

Submission status: Wrong Answer

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

mod = n % k

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

Submission status: Wrong Answer

Solution code:
a,b = 7,4
x = a-b
y = b-x
print(y)

Submission status: Wrong Answer

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

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

m = min(n, m)
m = min(abs(m-n),m)

print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
import math
a = n/k
b = math.ceil(a)
if abs(n-k) > n:
  print(n)
else:  
  x = n-(k*b)
  print(abs(x))

Submission status: Wrong Answer

Solution code:
data=input().split()
a=int(data[0])
b=int(data[1])
a=a%b
print(a)

Submission status: Wrong Answer

Solution code:
data=input().split()
a=int(data[0])
b=int(data[1])
while(a>=b):
    a=a%b
print(a)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
reminder = n % k

print(reminder)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int, input().split())
change = 1
ans_pre = N - K 
abs(ans_pre)
an1 = 0
while(change == 1):
  ans = ans_pre - K
  ans = abs(ans)
  if(ans < ans_pre):
    ans_pre = ans
    change = 1
    an1 = ans
  else:
    change = 0
    
print(an1)