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

x = (K+N)//K -1
print(x)
N -= x*K


print(N)

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

t = N//K
N -= t*K

while abs(N-K) < N:
    N -= K
print(abs(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())
temp = n
while temp < abs(temp - k):
    temp = abs(temp - k)

print(temp)

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

nnn = n % k

base = n
for i in range(100):
    xxx = abs(nnn - k)
    if xxx < n:
        base = xxx
    
    nnn = xxx

print(base)

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

nn = n // k
nnn = n - nn * k

base = n
for i in range(10000):
    xxx = abs(nnn - k)
    if xxx < nnn:
        base = xxx
    
    nnn = xxx

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, K = map(int,input().split())
q = N % K
ans = min(q, N-q)
print(ans)

N, K = map(int,input().split())
q = N % K
ans = min(q, K-q)
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):
from fractions import gcd

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

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

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

if k==1:
    print(0)
elif k==n:
    print(0)
else:
    n2=n%k
    n3=k-n2
    print(min(n2,n3))
    

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

n,k = map(int,input().split())
m = n
m = m%k
if m > int(k/2):
  ans = abs(m-k)
else:
  ans = m
print(ans)

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

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


n,k=map(int,input().split(" "))
 
r1= n%k;
 
r2=k-r1;
 
print(min(r1,r2))

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=[int(x) for x in input().split()]
print(min(abs(N-N//M*M),abs(N-(N//M+1)*(M))))N,M=[int(x) for x in input().split()]
print(min(abs(N-N//M*M),abs(N-(N//M+1)*(M))))

N,M=[int(x) for x in input().split()]
print(min(abs(N-N//M*M),abs(N-(N//M+1)*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 = map(int,input().split())
a = abs(K-N*(N//K))
b = abs(K-N*(N//K+1))
if a >= b:
    print(b)
else:
    print(a)

N,K = map(int,input().split())
a = abs(N-K*(N//K))
b = abs(N-(K*((N//K)+1)))
if a >= b:
    print(b)
else:
    print(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, K = map(int, input().split())

def okikae(t):
    if K/2 >= t and t <= K:
        print(t)
    elif N>K:
        print("0")
    else:
        okikae(abs(t-K))

okikae(N)

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

def okikae(t, k):
    if k==0:
        print(t)
    elif int(k/2)+1 > t:
        print(t)
    elif t%k==0:
        print(0)
    elif t>k and t%k > 0:
        t = k+(t%k)
        okikae(abs(t-k), k)
    else:
        okikae(abs(t-k), k)

okikae(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):
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math


N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = N % K
ans2 = (ans1 - K) * -1
print(ans1,ans2)
print(min(ans1,ans2))

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math


def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []
attack = 100000
while attack > 0:
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a.append(ue)
        a.append(ue+1)
    elif shimo == 9:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
    else:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
        a.append(ue+shimo+1)
    attack -= 1

print(b[K-1])

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math


N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = N % K
ans2 = (ans1 - K) * -1
# print(ans1,ans2)
print(min(ans1,ans2))

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

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

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

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

Verdicts: Runtime Error

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):
# -*- coding: utf-8 -*-

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

bef=-1
x =0
count = 0
Bool=True
if N%K < K:
	bef=N%K
	Bool=False
while Bool:
	if count>0:
		N=bef
	x=abs(N-K)
	count+=1
	if bef>=0 and bef<=x:
		break
	bef=x

print(bef)




# -*- coding: utf-8 -*-

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

t=N//K


ans = min(N - K * t, -(N - K * (t + 1)))
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())
flag = "F"

lenN = len(N)
lenK = len(K)
N = abs(N-K*(abs(len(N)-len(K)))) 

while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

import math

N , K = map(int, input().split())
flag = "F"
if N !=0:
    while 1:
        lenN = int (math.log10(N) + 1)
        lenK = int (math.log10(K) + 1)
        N = abs(N-K*(10**abs(lenN-lenK-1)))
        lenN = int (math.log10(N) + 1)
        if abs(lenN-lenK)<2:
            break



        
while 1:
    
    
    a = N
    N = abs(N - K)
    

    if a<=K and N <= K:
        if a < N:
            result = a
            flag="T"
        else:
            result = N
            flag="T"
    if flag == "T":
        break
print(result)

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):
a,b = input().split()
c = a % b
if b - c <= c :
  print(b - c)
else :
  print(c)

n, k = map(int,input().split())
a = n % k
b = k - a
if b <= a:
    print(b)
else:
    print(a)


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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, K = map(int, read().split())
    ans = N
    if N <= K:
        ans = N // K
    ans = min(ans, K - ans)
    return

if __name__ == '__main__':
    main()



import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, K = map(int, read().split())
    ans = N
    if N >= K:
        ans = N % K
    ans = min(ans, K - ans)
    print(ans)
    return

if __name__ == '__main__':
    main()



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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

x = gcd(max(k, n), min(k, n))
if n % k == 0:
    print(0)
elif n < k:
    print(min(n, abs(n - k)))
else:
    print(n % k)


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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

x = gcd(max(k, n), min(k, n))
if n % k == 0:
    print(0)
elif n < k:
    print(min(n, abs(n - k)))
else:
    exit(1)
    print(1)


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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

x = gcd(max(k, n), min(k, n))
if n % k == 0:
    print(0)
elif n < k:
    print(min(n, abs(n - k)))
else:
    print((n % k) % k)


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

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


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):
import fractions
import sys
N,K = map(int,input().split())
L = []
L.append(N)
i = 0
if N == K:
    print(N)
    sys.exit(0)
if N == 0:
    print(0)
    sys.exit(0)
if K == 1:
    print(0)
    sys.exit(0)
Q = 0
while True:
  L.append(abs(N-K))
  N = abs(N-K)
  i += 1
  if i > 10**5:
    Q = min(L)
    break
if (N%2 == 0 and K%2 == 0):
  if N > K:
    print(0)
    sys.exit(0)
  else:
    print(N)
    sys.exit(0)
if (N%2 != 0 and K%2 != 0):
  if N<K:
    print(N)
    sys.exit(0)
  else:
    print(min(N,abs(N-K),Q))
    sys.exit(0)
else:
  if N > K:
   	if N%K == 0:
      print(0)
      sys.exit(0)
    else:
      print(min(N,Q,fractions.gcd(N,K)))
      sys.exit(0)
  else:
    print(min(N,Q))
  

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


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

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

if N == 0:
    print(0)
    sys.exit(0)
if K == 1:
    print(0)
    sys.exit(0)
print(fractions.gcd(N,K))
  

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


answ = N%K
print(min(abs(answ),abs(answ-K)))


Verdicts: 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 = map(int, input().split())
over = n+1
while over > n:
  over = n
  n = abs(n-k)
  print(n,over)
print(over)

n,k = map(int, input().split())
if n % k == 0:
  print(0)
elif n % k <= 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):
n_k = [int(i) for i in input().split()]
n = n_k[0]
k = n_k[1]
r = n % k
r_1 = abs(r - k)
min = np.array([r, r_1]).min()
print(min)

import numpy as np
n_k = [int(i) for i in input().split()]
n = n_k[0]
k = n_k[1]
r = n % k
r_1 = abs(r - k)
min = np.array([r, r_1]).min()
print(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):
#c
n,k = map(int,input().split())
if n>=k:
    print(n%k)
else:
    if n<(k-n):
        print(n)
    else:
        print(k-n)


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


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):
K = int(input())
a = 0
count = 0
mm = [0,1]
while True:
    a += 1
    if a == 1:
        for i in range(1,10):
            count += 1
            if count == K:
                print(i)
                exit()

    elif a == 2:
        for i in range(1,10):
            for j in range(0,10):
                if abs(i-j)<=1:
                    count+= 1
                    mm.append(i*10+j)
                    if count == K:
                        print(i*10+j)
                        exit()

    elif a >= 3:
        tmp = [] 
        for i in range(1,10):
            # print(mm)
            for j in mm:
                b = j//(10**(a-2))
                # print(b)
                if abs(i-b) <=1:
                    count+= 1
                    e = i*(10**(a-1))+j
                    # print(count,e)
                    tmp.append(e)
                    if count == K:
                        print(e)
                        exit()
        # print(tmp)
        mm = mm + tmp

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

M = N % K
result = M if K -M > M else K-M
print(result)

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

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

list=[]


if N%K==0:
    print(0)
elif N%K==1:
    print(1)
elif N%K==2:
    print(2)
elif N%K==3:
    print(3)
else:
    while N not in list:
        list.append(N)
        N=abs(N-K)
    print(min(list))


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

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())
r=N%K
print(max(r,K-r))

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


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(abs(N-m*K),abs(N-m*(K+1))))

N,K=map(int,input().split())
m=N//K
print(min(abs(N-m*K),abs(N-(m+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, k = map(int, input().split())
if k == 1:
    print(0)
elif k == 2:
    if n % 2 == 0:
        print(0)
    else:
        print(1)
elif k == 3:
    if n%3 == 0:
        print(0)
    elif n%3 == 1:
        print(1)
    else:
        print(2)
elif k == 4:
    if n%4 == 0:
        print(0)
    elif n%4 == 1:
        print(1)
    elif n%4 == 2:
        print(2)
    else:
        print(3)
elif k == 5:
    if n%5 == 0:
        print(0)
    elif n%5 == 1:
        print(1)
    elif n%5 == 2:
        print(2)
    elif n%5 == 3:
        print(3)
    else:
        print(4)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

n, k = map(int, input().split())
def g(n,k):
    for i in range(k):
        if n%k == i:
            print(i)
if k == 1:
    print(0)
elif k == 2:
    g(n,k)
elif k == 3:
    g(n,k)
elif k == 4:
    g(n,k)
elif k == 5:
    g(n,k)
elif k == 6 or k == 7 or k == 8 or k == 9 or k == 10:
    g(n,k)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

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

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=n/k
if a >1:
    b=n%k
    if b==0:
        print(0)
    else:
        print(abs(b-k))
else:
    print(n)
    exit()

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

b = n % k
c = abs(b - k)
if b < c:
    print(b)
else:
    print(c)

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())
x1 = n%k
x2 = k - x1
print(min[x1, x2])

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


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())
r = N%K
s = s-r
print(min[r,s])

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

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

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())
print(min([N, N%K, N-N%K]))

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

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


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

else:
    nums=list()
    nums.append(N)
    while abs(N-K)<N:
        N=abs(N-K)
        nums.append(N)
    print(min(nums))

N, K=map(int,input().split())
t=N%K
ans=min(abs(t),abs(t-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=list(map(int,input().split()))
n=N%K
old_n=K+1
while True:
  if old_n<=n:
    print(old_n)
    break
  old_n=n
  N=abs(n-K)

N,K=list(map(int,input().split()))
n=N%K
old_n=K+1
while True:
  if old_n<=n:
    print(old_n)
    break
  old_n=n
  n=abs(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 op(n, k):
  return abs(n - k)


if __name__ == '__main__':
    n, k = map(int, input().split())
    print(abs(n % k))


if __name__ == '__main__':
    n, k = map(int, input().split())
    c = abs(n % k)
    r = min(c, k - c)
    print(r)
    

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):
l = input()
m = l.split(" ")
n = int(m[0])
k = int(m[1])
if n > k:
  n = n % k
  print(n)
if n < k:
  if n < (k-n):
    print(n)
  else:
    print(k-n)


l = input()
m = l.split(" ")
n = int(m[0])
k = int(m[1])
while a < n:
  a = abs(n-k)
  n = a
print(n)


l = input()
m = l.split(" ")
n = int(m[0])
k = int(n[1])
a = abs(n)-abs(k)
while a < n:
  n = a
  a = abs(n) - abs(k)
while a > n:
  n = n
print(n)


l = input()
m = l.split(" ")
n = int(m[0])
k = int(m[1])
if n > k:
  n = n//k
  if k = 1:
    n = 0
if n < k:
  n = n
  if n > k/2
  n = n-k
print(n)


l = input()
m = l.split(" ")
n = int(m[0])
k = int(n[1])
a = abs(n-k)
while a < n:
  n = a
  a = abs(n-k)
print(n)


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


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


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:
    print(n)
    exit(0)
elif n == k:
    print(0)
    exit(0)
else:
    pre_n = n
    while n > 0:
        temp = n % k
        if pre_n > temp:
            pre_n = n
            n = temp
        else:
            print(n)
            exit(0)

    print(n)


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

pre_n = float('inf')
while n > 0:
    temp = abs(n-k)
    if pre_n > n:
        pre_n = n
        n = temp
    else:
        print(n)
        exit(0)

print(n)


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


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

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

print(n)


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


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


n, k = map(int, input().split())
if n == 0:
    ans = n
elif k == 1:
    ans = 0
else:
    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, open(0).read().split())
a = N % K
print(min(K - b, b))


N, K = map(int, open(0).read().split())
a = N % K
print(min(K - a, a))

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 fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    print(fractions.gcd(N,K))

# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    a=fractions.gcd(N,K)
    N=N%K
    N=int(N/a)
    K=int(K/a)
    mi=N
    t=N
    for i in range(2):
        t=abs(t-K)
        mi=min(mi,t)
    print(mi*a)

# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    a=fractions.gcd(N,K)
    N=N%K
    N=int(N/a)
    K=int(K/a)
    mi=N
    t=N
    for i in range(N):
        t=abs(t-K)
        mi=min(mi,t)
    print(mi*a)

# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    a=fractions.gcd(N,K)
    N/=a
    K/=a
    mi=N
    t=N
    for i in range(2):
        t=abs(t-K)
        mi=min(mi,t)
    print(mi*a)

# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    a=fractions.gcd(N,K)
    N=N%K
    N=int(N/a)
    K=int(K/a)
    mi=N
    t=N
    for i in range(100):
        t=abs(t-K)
        mi=min(mi,t)
    print(mi*a)

# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    a=fractions.gcd(N,K)
    N=N%K
    N/=a
    K/=a
    mi=N
    t=N
    for i in range(2):
        t=abs(t-K)
        mi=min(mi,t)
    print(mi*a)

# coding:utf-8
import math
import fractions

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

if K==0:
    print("N")
elif N==0 or N%K==0:
    print("0")
else:
    mi=N
    t=N
    for i in range(math.ceil(N*1.0/fractions.gcd(N,K))):
        t=abs(t-K)
        mi=min(mi,t)
    print(mi)

# coding:utf-8
import math
import fractions

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

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

Verdicts: Wrong Answer

Wrong Answer

Time Limit Exceeded

Wrong Answer

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):
import sys
sys.setrecursionlimit(100000000000000000)

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

def a(N, K):
    if abs(K - N) < K / 2:
        print(abs(K - N))
    else:
        a(abs(K - N), K)
        

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


#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n, k;
    scanf("%d %d", &n, &k);
    if (k == 1){
        printf("0\n");
    }else{
        while ((double)n >= (double)k / 2){
            n = abs(k - n);
        }
        printf("%d\n", n);
    }
    return 0;
}


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

if k > n:
    tmp = n
else:
    tmp = n % k

if tmp > k / 2:
    tmp = k - tmp

print(tmp)
    


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())
if n > 0:
  n = n-k
elif n <= 0:
  break
m = abs(n)
l = abs(m-k)
print(min(m,l))

n,k = map(int,input().split())
if n > 0:
  n = n-k
elif n == 0:
  n = 0
else:
  break
m = abs(n-k)
print(min(n,m))

n,k = map(int,input().split())
if n > 0:
  n = n-k
elif n == 0:
  n = 0
else:
  m = abs(n-k)
print(min(n,m))

n,k = map(int,input().split())
if n > 0:
  n = n-k
elif n == 0:
  n = 0
else:
  m = abs(n-k)
print(min(n,abs(n-k))

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

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


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):
num=input().rstrip().split(" ")
num1=int(num[0])
num2=int(num[1])
result=1
list0=[num1]
while result>0:
  result=num1-num2
  if result<0:
    result=-result
    list0.append(result)
    break
  else:
     list0.append(result)
list0=sorted(list0)
print(list0[0])

num=input().rstrip().split(" ")
num1=int(num[0])
num2=int(num[1])
if num1%num2==0:
  print(0)
else:
  date0=num1%num2
  date1=num2-date0
  if date0>date1:
    print(date1)
  else:
    print(date0)

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 math

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

b = n % k

print(b)

#c = abs(k-b)

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

print(ans)

import math

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

b = n % k

#print(b)

c = abs(k-b)

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

print(ans)

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())
int H = 0
while True:
  if (N > K):
    H = N-K
  else:
    H = K - N
  if (H>N):
    break
  else:
    N = H
print(N)
  

N,K = map(int,input().split())
H = 0
while True:
  if (N > K):
    H = N%K
  else:
    H = K-N
  if (H>N):
    break
  else:
    N = H
print(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):
n, k = map(int, input().split())
L = []
if n > k:
  n = n - k*(n//k)
 
if n*2 <= k:
  print(n)
else:
  print(k)

n, k = map(int, input().split())
L = []
if n > k:
  n = n - k*(n//k)
 
if n*2 <= k:
  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):
if __name__ == "__main__":
	N, K = list(map(int, input().split()))
    r = N%K
    print(r) if r < abs(r-K) else print(abs(r-K))


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


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())
N = N%K
min_num = 0
while True:
  if (N==0):
    min_num = N
    break
  elif N in history:
    min_num = min(history)
    break 
  history.append(N)
  N = abs(N-K)

print(min_num)

      


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

middle = N % K
answer = middle
while True:
  if abs(answer-k) > N:
    answer = N
    break
  if abs(answer - K) < answer:
    answer = abs(answer-K)
  else:
    break
    
print(str(answer))

N, K = map(int, input().split())
N = N%K
history = []
min_num = 0
while True:
  if (N==0):
    min_num = N
    break
  elif N in history:
    min_num = min(history)
    break 
  history.append(N)
  N = abs(N-K)

print(min_num)

      


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

if N < K:
    print(N)
elif N % K == 0:
    print(0)
else:
    a = N // K
    b = N - (a * K)
    c = abs(N - a)
    print(c)

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

if N <= K:
    print(N)
elif N % K ==0:
    print(0)
else:
    a = N // K
    b = N - (a * K)
    c = abs(N - a)
    print(c)

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

if N < K:
    print(N)
else:
    a = N % K
    b = abs(a-k)
    if a<b:
      print(a)
    else:
      print(b)
      


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

if N < K:
    print(N)
elif N % K == 0:
    print(0)
else:
    a = N % K
    if a<k:
      print(a)
    else:
      print(k)
      

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

if N <= K:
    print(N)
elif N % K ==0:
    print(0)
else:
    a = N // K
    b = N - (a * K)
    c = abs(N - b)
    print(c)

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

a = N % K
b = abs(a-K)
if a<b:
    print(a)
else:
    print(b)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

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


def main(n, k):
    print(n, k)
    if n % k == 0:
        # print('n%k=0')
        res = 0
    else:
        
        res = min(n % k, abs((n % k) - k), n)

    print(res)


main(N, K)
# main(7, 4)
# main(2, 6)
# main(1000000000000000000, 1)
# main(9, 6)


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


def main(n, k):
    amari = n % abs(n - k)

    if amari == k:
        return 0
    else:
        return min(amari, n)


print(main)

# main(7,4)
# main(2,6)
# main(1000000000000000000 ,1)


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


def main(n, k):
    # print(n, k)
    if n % k == 0:
        # print('n%k=0')
        res = 0
    else:
        
        res = min(n % k, abs((n % k) - k), n)

    print(res)


main(N, K)
# main(7, 4)
# main(2, 6)
# main(1000000000000000000, 1)
# main(9, 6)


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
b=k-a
print(a,b)

n,k=map(int,input().split())
a=n%k
b=k-a
print(min(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())
from fractions import gcd
ans = gcd(N,K)


print(ans)
#print(*ans,sep=' ')

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

N,K = map(int, input().split())
from fractions import gcd
ans = gcd(N,K)
if N%K==0:
  ans = 0


print(ans)
#print(*ans,sep=' ')

N,K = map(int, input().split())
print(min(N%K,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):
n, k = list(map(int, input().split(' ')))
result = 0
if k < n:
    result = n % k
elif n < k:
    result = min(n, k-n)
print(result)

n, k = list(map(int, input().split(' ')))
result = 0
if k < n:
    result = n % k
elif n < k:
    result = n
print(result)

n, k = list(map(int, input().split(' ')))
result = 0
if k < n:
    result = min(n%k, k-(n%k))
elif n < k:
    result = min(n, k-n)
print(result)

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

min_0 = N
min_1 = abs(N-m*K)
min_2 = abs(min_1-K)

print(min(min_0, min_1, min_2))N,K=map(int, input().split())
m=int(N/K)

min_0 = N
min_1 = abs(N-m*K)
min_2 = abs(min_1-K)
m=int(min_2/K)
min_3 = abs(min_2-m*K)

print(min(min_0, min_1, min_2, min_3))

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

min_0 = N
min_1 = abs(N-m*K)
min_2 = abs(min_1-K)
m=int(min_2/K)
min_3 = abs(min_2-m*K)

print(min(min_0, min_1, min_2, min_3))


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):
def absolute(N,K):
    return abs(N-K)
    
N,K=map(int,input().split())
N=N%K
valuelist = [N%K]

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


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

s = n % m

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

minus = abs(minus)

print(min(plus, minus))


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


minimum = n % k


while n%k > k-n%k:
    minimum = k - n % k 
    n = k - n % k  

print(minimum)

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

a = N // K
b = abs(N - (K*a))
c = abs(N - (K*(a+1)))
print(min(b, c))

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

a = N // K
b = abs(N - (K*a))
c = abs(N - (K*(a+1)))
print(min(b, c))

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

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


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

print(N % K)

N, K = list(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):
NK = input().split();
N,K = int(NK[0]),int(NK[1]);
min = N;


if(K == 1):
    while(int(len(str(N))) > 2):
        N = int(N - K * (N / 2));
else:
    border = math.floor(N / K);
    N = N - K * border;
        
flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(min);

import math

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


if(K == 1):
    while(int(len(str(N))) > 2):
        N = int(N - K * (N / 2));
else:
    border = math.floor(N / K);
    N = N - K * border;
        
flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(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())
print(N%K)

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


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

rem = n % k
a = rem - k
ans = min(abs(a)


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

if k == 0:
	ans = n
else:
	rem = n % k
	a = rem - k
	ans = min(abs(a), rem)

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

while S > 0:
  N = abs(S)
print(N)

N, K = list(map(int,input().split()))
d = N//K
S0 = N - d * K
S1 = S0 - K
Sa = abs(S1)
if S0 <= Sa:
  print(S0)
else:
  print(Sa)

Verdicts: Wrong Answer

Accepted