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):
x = list(map(int,input().split(" ")))
n = x[0]
k = x[1]
import math
l = abs(n % k)
print(l)

if l > k//2:
    print(k-l)
else:
    print(l)

x = list(map(int,input().split(" ")))
n = x[0]
k = x[1]
import math
l = abs(n % k)
# print(l)

if l > k//2:
    print(k-l)
else:
    print(l)

Verdicts: Wrong Answer

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

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

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

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

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

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

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

#coding:utf-8

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

r1 = n % k
r2 = abs(k - r1)

ans = min(r1,r2)

print("{}".format(ans))


Verdicts: Wrong Answer

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())
def sousa(x):
    x = abs(x - k)
    return x
before_n = n
cnt = -1
while before_n >= n:
    before_n = n
    n = sousa(n)
    cnt = cnt + 1
print(cnt)

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

z = a % b

if z > b/2:
    print(abs(z-k))
else:
    print(z)

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


z = a % b


if z > b/2:
    print(abs(z-b))
else:
    print(z)

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 math
import fractions
N,K = map(int,input().split())
if (min(N,K))<2:
    print (0)
else:
    print(fractions.gcd(N, K))

#import math
import fractions
N,K = map(int,input().split())
if (N==0 or K==1)<2:
    print (0)
else:
    print(fractions.gcd(N, K))

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

Verdicts: Wrong Answer

Wrong Answer

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

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

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

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

print(m)


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

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


Verdicts: Wrong Answer

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

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

N, M = map(int, input().split())
result = []
while N > 0
    M -= abs(N - M)
    result.append(M)
print(min(result))

N, K = map(int, input().split())
N = abs(N - K)
while true:
  if N =< K:
    N = (N - K)
    break
    
print(abs(N))

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

Verdicts: 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:
    print(N)
elif N%K == 0 :
    print(0)
elif abs(N-K) < K:
    print(abs(N-K))
else:
    print(abs(N-(K*((N//K)+1))))


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

Verdicts: Wrong Answer

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

Submission attempts (in order):
n,k = map(int,input().split())
if n % k ==0:
print(0)
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))

x,y,z = list(map(int,input().split()))
def swap(a,b):
tmp = a
a = b
b = tmp
return (a,b)
x,y = swap(x,y)
x, z = swap(x, z)
print(x,y,z)
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))

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

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

n, k = [int(x) for x in 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(0)
  exit()
l = k%n
print(min(l, k-l))

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

import math
x = math.floor(n/k)

ans = 10**20
for i in range(-100, 101, 1):
    if ans > abs(n-(x-i)*k):
        ans = abs(n-(x-i)*k)
        print(ans)

print(ans)

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

import math
x = math.floor(n/k)

ans = 10**20
for i in range(-100, 101):
    if ans > abs(n-(x-i)*k):
        ans = abs(n-(x-i)*k)
        print(ans)

print(ans)

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

ans = min(n%k, k-n%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):
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
mod = N % K
print(mod, abs(K - mod))

from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().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 = input().split()

if N >= K:
	N %= K

if ( K / 2 ) >= N:
	print ( N )

else:
    print ( K - N )

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

Verdicts: Runtime Error

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

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

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


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

print(n % k)


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

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

print(min_n)


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):
def resolve():
    import math
    n, k = map(int, input().split())
    if n < k:
        print(n)
    elif k == 1:
        print(0)
    else:
        while True:
            _n = abs(n-k)
            if n > _n:
                n = _n
            else:
                print(_n)
                break

resolve()

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

resolve()

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())
ans=gcd(N,K)
if K==1 or N==0:
    ans=0
print(ans)

def main():
    N,K=map(int, input().split())
    ans=N
    for i in range(100000):
        N=N%K
        ans=min(ans,N)
        if N==0:
            break
        N=-N
    print(ans)

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

num=list(map(int, input().split()))
if num[0]%num[1]<=num[1]-(num[0]%num[1]):
  ans=num[0]%num[1]
else:
  ans=num[1]-(num[0]%num[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 = int(input())

while N <= int(K/2):
  N = min([abs(N-K), N % K])

print(N)

N, K = list(map(lambda n: int(n), input().split(" ")))
 
while N <= int(K/2):
  N = min([abs(N-K), N % K])

print(N)

N, K = list(map(lambda n: int(n), input().split(" ")))
 
while N > int(K/2):
  N = min([abs(N-K), N % K])

print(N)

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

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


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

a = abs(N - K)
ans = N % a

if ans == 1:
    print(0)
else:
    print(ans)

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

a = abs(N - K)
ans = N % a

if ans == 1:
    print(0)
else:
    print(ans)

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

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
n, m = map(int, input().split())
a = list(map(int, input().split()))
num = sum(a)
cnt = 0
for i in range(n):
    if a[i] < num/(4*m):
        continue
    else:
        cnt += 1
if cnt >= m:
    print("Yes")
else:
    print("No")   

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):
li = list(map(int, input().split()))
n = li[0]
k = li[1]
if n % k <= abs(n - k):
    print(n % k)
else:
    print(abs(n - k))

li = list(map(int, input().split()))
n = li[0]
k = li[1]
a = n % k
b = abs(a - k)
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())
N, K = map(abs, (N,K))
amari = N%K
if amari == 0:
    print(0)
else:
    amari2 = K - amari
    print(max(amari, amari2)

N, K = map(int, input().split())
N, K = map(abs, (N,K))
amari = N%K
if amari == 0:
    print(0)
else:
    amari2 = K - amari
    print(max(amari, amari2)

N, K = map(int, input().split())
N, K = map(abs, (N,K))
amari = N%K
if amari == 0:
    print(0)
else:
    amari2 = K - amari
    print(min(amari, amari2))

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

s = N % K

print(min(abs(s), abs(K-s))

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

s = N % K

print(min(s, K-s))

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 ==0:
  print(0)
  exit()
elif N <0:
  N = abs(N - K)

mod = N % K

print(min(mod, abs(mod + K)))

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

mod = N % K

print(min(mod, abs(mod + K)))

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

a = N%K
ans = min(a, K-a)

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

if n < k:
    if k - n > n:
        print(n)
    else:
        print(k - n)
else:
    if n % k == 0:
        print(0)
    else:
        print(fractions.gcd(n, k))

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

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

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

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

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

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__':
    s = input().rstrip().split(' ')
    N,K = int(s[0]), int(s[1])
    cand1 = abs(N - K*math.ceil(N/float(K)))
    cand2 = abs(N - K*math.floor(N/float(K)))
    print(min(cand1, cand2))


import math

if __name__ == '__main__':
    s = input().rstrip().split(' ')
    N,K = int(s[0]), int(s[1])
    if(N>=K):
        
        
        cand1 = int(N%K)
        cand2 = int(K-(N%K))
        print(min(cand1, cand2))
    else:
        print(min(int(abs(N-K)),N))


Verdicts: Runtime Error

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

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

K = N%X

if K >= X:
  print(X)
else:
  print(K)

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

K = N%X
k = X - K

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

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

N, K = [int(n) for n in input().split()]
print(0 if K==1 or N==0 or N==K else fractions.gcd(N, K))


import fractions

N, K = [int(n) for n in input().split()]
print(0 if K==1 else fractions.gcd(N, K))


N, K = [int(n) for n in 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())
if n <= k:
    print(n)
else:
    print(n%k)

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
N,K = map(int,input().split())
num = 0
while N <= num:
  num = N
  N = abs(N - K)

print(num)

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

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

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

Verdicts: Wrong Answer

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:
    N = N%K
    number_list = [N]
else:
    number_list = [N]

print(min(number_list))

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

s=math.floor(n/k)

print(min(abs(n-s*k),n))

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

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

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


n, k = map(int, input().split())
mod = n % k
if abs(mod) > abs(mod-k):
    print(abs(mod-k))
else:
    print(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=int(input().split())
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)

n,k=input().split()
n=int(n)
k=int(k)
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)

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):
##161 C
N,M= map(int, input().split())
amari= N % M
if(amari<=(N/2)):
    print(amari)
else:
   amari = amari-M
   print(amari)


##161 C
N,M= map(int, input().split())
amari= N % M
if(amari<=(M/2)):
    print(amari)
else:
   amari = abs(amari-M)
   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):
N,K = map(int,input().split())

def replace(N,K):
    if(K == 1 or N==K):
        return 0
    else:
        flag = 0
        while(abs(N-K)>=0):
            N = abs(N-K*round(N/K))
            if(N == 0 ):
                return 0                
            elif (N-K<0):
                return abs(N-K)
        return N
print(replace(N,K))

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

def replace(N,K):
    if(N<K):
        return N
    else:
        a = N%K
        if (abs(a-K)<K):
            a = abs(N-K)
    return a

print(replace(N,K))

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

def replace(N,K):
    if(N<K):
        return N
    else:
        a = N%K
        if (abs(a-K)<K):
            a = abs(N-K)
        else:
            a = abs(N-K) + abs(N-a)  
    return a

print(replace(N,K))

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

def replace(N,K):
    if(K == 1):
        return 0
    elif(N<K):
        return N
    else:
        N = N%K
        if (abs(N-K)<=K):
            N = abs(N-K)
    return

print(replace(N,K))

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

def replace(N,K):
    if(K == 1):
        return 0
    if(N>=K):
        while(N>=K):
            N = abs(N - K)
            if(N<K):
                break
        return N
    else:
        return N

print(replace(N,K))

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

def replace(N,K):
    if(K == 1 or N==K):
        return 0
    if(N<K):
        return N
    else:
        while(N-K>0):
            N = N-(K*(N//K))           
            if (N-K<=0 and abs(N-K)>=K):
                return abs(N-K)

print(replace(N,K))

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

def replace(N,K):
    a = N%K
    return min(a,abs(a-K))

print(replace(N,K))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n, m = map(int, input().split())
if n <= m:
  print(n)
else:
  print(m // 2)

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

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

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 = map(int, input().split())
Abs = abs(N - K)
if N <= K:
    while True:
        if N > Abs:
            N = Abs
        else:
            break
else:
    N = N % K + K
    while True:
        if N > Abs:
            N = Abs
        else:
            break
print(N)

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

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

c = math.ceil(nk[0]/nk[1])
x = nk[0] - nk[1]*c
p = x+nk[1]
print(str(c)+','+str(x)+','+str(p))
print(abs(x) if abs(x) < p else p)

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

x = nk[0]%nk[1]
p = abs(x-nk[1])
print(x if x < p else p)

Verdicts: Wrong Answer

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

Submission attempts (in order):
import sys

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

tmp = N

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

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

import sys

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

tmp = N

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

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

import sys

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

tmp = N

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

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

import sys

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

tmp = N

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

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

import sys

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

tmp = N

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

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

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

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

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

Verdicts: Runtime Error

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(x) for x in input().split(" ")]

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

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

if N ==0 or K==1 or N == K:
  print(0)
else:
  while N>abs(N-K):
    N = abs(N%K-K)
  print(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 numpy as np
N,K=map(int,input().split())
print(N%K)



import numpy as np
N,K=map(int,input().split())
a=np.abs(N%K)
print(min(a,np.abs(a-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(0)

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


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

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


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

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


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




# SN = N
# PN = float('inf')
# while PN > N:
#     PN = N

#     print(PN, N)

if N == K:
    print(0)

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


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



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



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)



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

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

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 = map(int, input().split())
list = [n]
list.append(abs(n-k))
while(list[-1] >= list[-2]):
	n = abs(n-k)
	list.append(n)

print(min(list))

n, k = map(int, input().split())
list = [n]
list.append(abs(n-k))
while(list[-1] < list[-2]):
	n = n-k
	list.append(n)

print(min(list))

n, k = map(int, input().split())
list = [n]
list.append(abs(n-k))
while(abs(list[-1]) >= abs(list[-2])):
	n = abs(n-k)
	list.append(n)

print(min(list))

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

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):
from fractions import gcd
NK = input().split()
N = int(NK[0])
K = int(NK[1])
if N==1 or K==1:
    print(0)
    exit()
else:
    print(gcd(N,K))



from fractions import gcd
NK = input().split()
N = int(NK[0])
K = int(NK[1])
if N==1 or K==1:
    print(0)
    exit()
elif N==0:
    print(K)
else:
    print(gcd(N,K))

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

num = list(map(int, input().split()))
print(min([num[0],num[0]%num[1],abs((num[0]//num[1])-num[1])]))

num = list(map(int, input().split()))
print(min([num[0],num[0]%num[1],abs((num[0]%num[1])-num[1])]))

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 = int(input())
tmp = [i for i in range(1, 10)]
ans = list(tmp)
for i in range(10):
    tmp2 = []
    for x in tmp:
        k = int(str(x)[-1])
        if k != 0:
            ans.append(10*x-1 + k)
            tmp2.append(10*x-1 + k)
        if k != 9:
            tmp2.append(10*x+1 + k)
            ans.append(10*x+1 + k)
        tmp2.append(10*x + k)
        ans.append(10*x + k)
    tmp = list(tmp2)

ans.sort()
print(ans[N-1])


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 = int(input())
nn = N
K = int(input())
n = 1
st = []
m = min(N, K)
while N >= abs(nn - n * m) :
    N = abs(N - K)
    n = n + 1
print(min(m, N))

N = int(input())
nn = N
K = int(input())
n = 1
st = []
m = min(N, K)
while N >= abs(nn - n * m) :
    N = abs(N - K)
    n = n + 1
    st.append(N)
    a = min(st)
print(min(m, a))


n, k = map(int,input().split())
m = n %k
print (min(m, abs(m-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,m = map(int,input().split())
a=map(int,input().split())
a=sorted(a)
if a[-m] >= sum(a)/4/m:
    print("Yes")
else:
    print("No")

n,m = map(int,input().split())
div = n//m
minval = div*m
maxval = (div+1)*m
print(min(abs(minval-n),abs(maxval-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):
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    ans=n
    dis=abs(ans-k)
    if n>=k:
        print(n%k)
        exit()
    else:
        while ans>dis:
            ans=dis
            dis=abs(ans-k)
    print(ans)



if __name__ == "__main__":
    main()

from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    if n>=k:
        n%=k
        print(k%n if n!=0 else 0)
        exit()    
    print(n if n<=k//2 else k-n)



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

N = [abs(n - ik) for i in range(n)]
ans = min(N)
print(ans)
        

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

m = n % k
m1 = k - m

if m > m1:
  ans = m1
else:
  ans = m
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 = [int(i) for i in input().split()]
print(N%K)

N,K = [int(i) for i in input().split()]
if N%K==0:
  print(0)
else:
  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):
import sys

input = sys.stdin.readline

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

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

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



import sys

input = sys.stdin.readline

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

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

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



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

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

if __name__ == '__main__':
    main()


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

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())
x = n // k
y = x - 1
print(min(abs(n - k * x), abs(n - k * y), n))

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

n, k = map(int, input().split())
x = n // k
y = x - 1
z = x + 1
print(min(abs(n - k * x), abs(n - k * y), abs(n - k * z), 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):
k = input()
k = int(k)

if 1 <= k and k <= 12:
    print(k)
elif 13 <= k and k <= 35:
    temp = k-9
    q = temp // 3
    p = temp % 3
    
    s = ""
    s = s + str(q)
    if p == 0:
        s = s + str(q+1)
    elif p == 1:
        s = s + str(q)
    elif p == 2:
        s = s + str(q-1)
print(s)

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

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

Verdicts: Runtime Error

Accepted