peterverebics/CodeNet_Python_118 huggingface dataset:
a,b = map(int,input().split())
List=[int(i) for i in input().split()]
c = 1//(4*b)
d = 0
for i in range(a):
    if List[i] > c:
        d += 1
if d >= b:
    print("Yes")
else:
    print("No")
n,m=map(int,input().split())
a=list(map(int,input().split()))
a_sum=sum(a)
count=0
for i in a:
    if i>=a_sum/4*m:
        count+=1
if count>=m:
    print("Yes")
else:
    print("No")
n, m = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

if A[m-1] >= (sum(A) // (4 * m)):
    print("Yes")
else:
    print("No")
N,M = map(int,input().split())
A = input().split()
x = 0
sorted(A)
B = 0
for i in range(len(A)):
    B = B + int(A[i])
for i in range(len(A)):
    if int(A[i]) > int(B / (M * 4)):
        x = x + 1
if x > M - 1:
    print("Yes")
else:
    print("No")
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort(reverse=1)
    if A[M-1]>=sum(A)//(4*M):
        print('Yes')
    else:
        print('No')
    

if __name__ == '__main__':
    main()
N,M=[int(x) for x in input().split()]
A=[int(x) for x in input().split()]
su=sum(A)
count=0
for i in A:
    if i>=su//(4*M):
        count+=1
if count>=M:
    print("Yes")
else:
    print("No")
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
v = (sum(a) *1)//(4*m)
ans = [1 if i>=v else 0 for i in a[:m]]
print('Yes' if sum(ans) >= m else 'No')
n,m=map(int,input().split())
a=list(map(int,input().split()))
sort=sorted(a,reverse=True)
b=sum(a)
count=0
for i in sort:
  count+=1
  if i<b/4*m:
    break
if count-1<=m:
  print('Yes')
else:
  print('No')
N, M = map(int, input().split())
A = list(map(int, input().split()))
TOTAL = 0
for i in range(len(A)):
    TOTAL += A[i]
if A[-1] and A[-2] > (1/(4*M))*TOTAL:
    print("Yes")
else:
    print("No")
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a, reverse = True)
if b[m-1] >= 1 / (4 * m):
  print("Yes")
else:
  print("No")
n, m = map(int, input().split())
a = list(map(int, input().split()))

sorted(a, reverse=True)
if a[m-1] >= (sum(a)*(1/(4*m))):
    print("Yes")
else:
    print("No")
n, m = list(map(int, input().split()))
v = list(map(int, input().split()))
t = sum(v)/(4*m)

ct = 0
for i in v:
    if i>t:
        ct += 1
        
if ct >= m:
    print("Yes")
else:
    print("No")
def main():
    n, m, *a = map(int, open(0).read().split())
    k = sum(a)//(4*m)
    l = sum([i>=k for i in a])
    print('Yes' if l>=m else 'No')

if __name__ == '__main__':
    main()
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

aa = sorted(a, reverse=True)

suma = sum(aa)
threshold = suma / (4 * m)

if aa[m-1] > threshold:
    print("Yes")
else:
    print("No")
N,M = map(int,input().split())
A = list(map(int,input().split()))

a = sum(A)*(1/(4*M))
cnt = 0
for i in range(N):
    if A[i] > a:
        cnt += 1

if cnt >= M:
    print("Yes")
else:
    print("No")
n,m = map(int,input().split())
A = list(map(int,input().split()))
line = sum(A)/(4*m)
ans = 0
for a in A:
  if a > line:
    ans += 1
if ans >= m:
  print('Yes')
else:
  print('No')
number = input().split(" ")
N = int(number[0])
M = int(number[1])
A = input().split(" ")

a = 0
for i in A:
    a += int(i)
A_i = [int(s) for s in A]
A_i.sort()

x = 0
for j in range(M):
    if int(A_i[-1-j]) >= int(a/(4*M)):
        x += 1
    else:
        pass

if x == M:
    print("Yes")
else:
    print("No")
n,m=map(int,input().split())
a = list(map(int, input().split()))

if sum(a) / 4 / m <= a[m-1]:
    print("Yes")
else:
    print("No")
n, m = map(int, input().split())
arr = list(map(int, input().split()))
p = sum(arr)
c = 0
for i in arr:
    if i >= p//(4*m):
        c += 1
if c>= m:
    print("Yes")
else:
    print("No")
from sys import stdin
N,M = map(int,input().split())
A=  [int(x) for x in stdin.readline().rstrip().split()]
m = max(A)
s = sum(A)
if ( s / (4 * M) > m) :
  print("no")
else:  
  print("yes")
a,b=map(int,input().split())
n=list(map(int,input().split()))
c=sum(n)/(4*b)
d=[i for i in n if i>=c]
print(a,b,c,d,sum(n))
if b>len(d):
    print('No')
else:
    print('Yes')
count=0
n,m=map(int,input().split())
a=list(map(int,input().split()))

for i in range(n):
    if a[i]<sum(a)//(4*m):
        pass
    else:
        count+=1
if count>=m:
    print("Yes")
else:print("No")
n,m = input().split(" ")
alist = input().split(" ")

n = int(n)
m = int(m)

sum = 0
for i in alist:
    sum += int(i)

l = sum * (1 / (4*m))

c = 0

for k in alist:
    if int(k) > l:
        c += 1

if c >= m:
    print("Yes")
else:
    print("No")
n,m = map( int, input().split())
a = list( map( int, input().split()))

d = int((1/(4*m)) * sum(a))
count=0
for x in a:
    if x>=d:
        count+=1

if count>=m:
    print("Yes")
    
else:
    print("No")
N,M = map(int,input().split())
A = list(map(int,input().split()))
s = sum(A)
A = sorted(A, reverse = True)
if A[M-1] >= s//(4*M):
  print("Yes")
else:
  print("No")
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
ad=sum(a)
ad=ad//(4*m)


for i in range(m):
    if a[i]<ad:
        print("No")
        break
else:
    print("Yes")
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=1)
print("Yes" if 4*m*a[m-1]>sum(a) else "No")
a,a1 = input().split()
b = input().split()
sum = 0
for _ in b:
    sum += int(_)
if int(b[int(a1) - 1]) < sum/4:
    print("Yes")
else:
    print("No")
q,p= input().split()
a,b =(int(p), int(q))
s = input().split()
total = 0
for i in range(b):
    total += int(s[i])
if total >= a:
    print('Yes')
else:
    print('No')
import numpy as np
n, m = map(int, input().split())
A = np.array([int(i) for i in input().split()], dtype=np.float64)
A -= sum(A) / (4 * m)
print('Yes' if np.sum(A > 0) >= m else 'No')
nums = list(map(int, input().split()))
n = nums[0]
m = nums[1]

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

sum = 0
for v in a:
  sum += v

result = []
for s in a:
    if s >= sum * (1 / (4 * m)):
        result.append(s)
print(result)
if len(result) >= m:
    print("Yes")
else:
    print("No")
N, M = map(int, input().split())
score_list = list(map(int, input().split()))
s = sum(score_list)
print(s)
print(score_list)
for score in score_list:
    if score < (s / (4 * M)):
        score_list.remove(score)
print(score_list)
if len(score_list) >= M:
    print('Yes')
else:
    print('No')
#import numpy as np
import math


def solve():
    tv = sum(a)
    min_votes = math.ceil(tv * 1/4 / m)
    print(min_votes)
    cnt = 0
    for ai in a:
        if ai>=min_votes:
            cnt+=1
    if cnt>=m:
        print("Yes")
    else:
        print("No")
    return


#s = input()

n, m = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
solve()
N,M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
S = sum(A)

if A[M-1]>S/(4*M):
    print('Yes')
else:
    print('No')
def popularity(votes, N, M):
    
    total_votes = sum(votes)
    coef = 1.0 / (4.0 * M)
    limit = coef * total_votes
    
    cnt = 0
    for vote in votes:
        if vote > limit:
            cnt += 1
        if cnt == M:
            return "Yes"
    
    return "No"
  
N, M = [int (x) for x in input().split()]
votes = [int (x) for x in input().split()]
popularity(votes, N, M)
cl1 = input().split()
cl2 = input().split()
n = int(cl1[0])
m = int(cl1[1])
cl1 = [int(s) for s in cl1]
cl2 = [int(s) for s in cl2]

sum= 0.0
for i in range(n):
    sum = cl2[i]+ sum
print(sum)
cl2 = sorted(cl2,reverse=True)
if(cl2[m-1] > sum//(4*m)):
    print("Yes")
else:
    print("No")
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = sum(x > sum(A) // 4 // M for x in A)
print('Yes' if ans >= M and ans != N else 'No')
n,m=map(int,input().split())
a=list(map(int,input().split()))
count=0
b=sum(a)
for i in range(n):
 if a[i]>=b//(4*m):
  count=count+1
if count>=m:
 print("Yes")
else:
 print("No")
N, M= list(map(int, input().split()))
A= list(map(int, input().split()))
A.sort(reverse = True)
B = A[0:M]
C = B[-1]
Sum =  sum(A)
if C >Sum /(4*M):
    print("Yes")
else:
    print("No")
from fractions import Fraction
N, M = map(int, input().split())
A = list(map(int, input().split()))
sum_p = sum(A) * Fraction(1, M * 4)
count = 0
for i in A:
    if i > int(sum_p):
        count += count + 1
if M <= count:
    print("Yes")
else:
    print("No")
N, K=map(int, input().split())
min=min(N%K, abs((N%K)-K))
print(min)
N, K = map(int, input().split())

if N<K:
    if N>K/2:
        print(K-N)
    else:
        print(N)

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

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

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

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

res = N % K
print(min(res, abs(res - K)))
def main():
    N, K = (int(i) for i in input().split())
    a = N - (N//K)*K
    print(min(a, abs(a-K)))


if __name__ == '__main__':
    main()
n, k = map(int, input().split())
x = n % k
print(min(x, k-x))
N, K = map(int, input().split())
A = N % K
B = abs((N % K)-K)
print(min(A, B))
n,k=map(int,input().split())
ans=n
nex=n
w=n//k
#print(w)
nex=n-k*w
if ans>nex:
  ans=nex
#print(nex,ans)
while (nex<=k and nex>(k-nex)) and ans!=0:
  nex=k-nex
  if nex<ans:
    ans=nex
  if ans==0:
    break
print(ans)
n, k = map(int,input().split())

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

if(N <= K):
    ans = min(abs(N-K), abs(abs(N-K)-K))
    print(ans)
else:
    mod = N%K
    ans = min(abs(mod-K), mod)
    print(ans)
#!/usr/bin/env python3
n, k = map(int, input().split())
print(min(n, n-n//k*k, (n+k-1)//k*k-n))
i = list(map(int, input().split()))

j = i[0] % i[1]
k = i[1] -j

print(min(j,k))
import sys
from math import sqrt
from collections import Counter, defaultdict

input = sys.stdin.readline


def I():
    return int(input())


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


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, k = MI()
    mod = n % k
    if mod > abs(mod - k):
        print(abs(mod - k))
    else:
        print(mod)

    pass


if __name__ == "__main__":
    main()
N,K = map(int, input().split())
xo=N%K
xn=abs(xo-K)
while True:
    if xo>xn:
        xo=xn
        xn=abs(xn-K)
    else:
        break
print(xo)
N, K = list(map(int, input().split()))

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

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

a1=n%k
a2=abs(a1-k)
print(min(a1,a2))
n,k = map(int, input().split())
r = n % k
s = abs(r - k)
print(min(r,s))
n,k=map(int,input().split())
if n<k:
    if k-n<n:
        print(k-n)
    else:
        print(n)

elif n%k==0:
    print(0)
else:

    a = n // k
    b= (a + 1) * k - n
    c = n - a * k
    t=n-k
    p=k//t
    r=k-p*t
    print(min(b,c,r))
n,k=list(map(int,input().split()))
n=n%k
m=k-n
print(min(m,n))
n,k=map(int,input().split())
print(min(n%k,abs(n%k-k)))
n,k = map(int,input().split());
i = 0;
if n == k:
    print(0);
elif n < k:
    print(min(n,k-n));
else:
    v = (n - k)%k;
    if v*2 >= k:
        print(k-v);
    else:
        print(v);
# coding: utf-8

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

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

if n % k == 0:
  print(0)
else: 
  ans = n % k
  #print(ans)
  while ans > k//2:
    n = abs(ans - k)
    ans = min(n, ans)
  print(ans)
N, K = map(int, input().split())

x = N % K
print(min(x, abs(K-x)))
N,K=map(int,input().split())
x=N%K
if x<=K/2:
    print(x)
else:
    print(K-x)
n,k = map(int,input().split())
answer = 0
if k >= n:
  gap = k-n
  if gap > n:
    answer = n
  else:
    answer = gap
else:
  sho = n // k
  if n % k == 0:
    dec = sho - 1
  else:
    dec = sho
  n = n - k*dec
  if k >= n:
    gap = k-n
    if gap > n:
      answer = n
    else:
      answer = gap
print(answer)
n, k = map(int, input().split())

x = n % k
print(min(abs(x-k), x))
# 初期入力
N,K = (int(x) for x in input().split(" "))

#
zeroika = 0
if K <N:
    zeroika = N//K
else:
    zeroika = 1
N1 =abs(N-K*zeroika) #N1がマイナスになって初めてABS、そこまではKの倍数単調に減る
while N1<N:
    N =N1
    N1 =abs(N-K)
    #print(N1,end=" ")
print(N)
N,K = map(int,input().split())
S,A = divmod(N,K)
print(min(A,abs(A-K)))
N,K = map(int,input().split())
a = N % K
if K - a < a:
    print(K-a)
else:
    print(a)
n,k = list(map(int, input().split()))

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

x = abs(n%k)
y = abs(n%k - k)
print(min(x,y))
N, K = map( int, input().split())
# if N%K == 0:
#     print(0)
#     return
print( min(N%K, K - N%K))
N,K = map(int, input().split())

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

lst = []
lst.append(a)
lst.append(b)
print(min(lst))
n,k =map(int,input().split())
if n%k==0:
  print(0)
else:
  print(min(n%k,abs((n%k)-k)))
N, K = map(int, input().split(' '))
print(min(N % K, abs((N % K) - K)))
N, K = [int(a) for a in input().split()]

num_count = (N-N%K)//K
ans = min(abs(N - num_count*K), abs(N - (num_count+1)*K))
if num_count > 0:
    ans = min(abs(N - (num_count-1)*K), ans)
print(ans)
N, K = map(int, input().split())
a = abs(N - (N // K) * K)
b = abs(a - K)
print(min(a, b))
n,k = map(int,input().split())

if (n % k) > abs(n % k -k):
    print(abs(n%k-k))
else:
    print(n%k)
n,k=map(int,input().split())
if n >= k:
    print(min(n%k,k-n%k))
elif n == 0:
    print(n)
else:
    print(min(n,k-n))
string = input()
n = int(string.split()[0])
k = int(string.split()[1])

diff = n - k
n = n - (diff // k) * k

while n > k:
    n = n - k

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

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

a = int(N/K)
b = N % K
c = abs(b-K)


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

ans = min(N % K, (K - (N % K)) % K)
print(ans)
from sys import stdin,setrecursionlimit
n,k = map(int,stdin.readline().rstrip().split())
print(min(n%k,k-n%k))
N, K = map(int, input().split())
print(min(N%K, abs(N%K-K)))
n, k = map(int, input().split())
ans1 = n%k
ans2 = -(ans1-k)

print(min(ans1, ans2))
N,K=map(int,input().split())
t=N%K
print(min(t,abs(t-K)))
N,K = map(int,input().split())
a = N%K
b = abs(a-K)
print(min(a,b))
n, k = list(map(int, input().split()))
if n < k:
    print(min(n, k-n))
else:
    print(min(n%k, k-(n%k)))
N, K = map(int, input().split())

ans = 0

ans_1 = N//K
ans_2 = ans_1 + 1

ans = min(abs(N-ans_1*K), abs(N-ans_2*K))
print(ans)
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
  N, K = map(int, input().split())

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

if __name__ == '__main__':
  main()
n, k = list(map(int, input().split()))
print(min(n%k, abs(n%k -k)))
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


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

x1 = n % k
x2 = k - x1
ans = min(x1, x2)

print(ans)
N, K = map(int, input().split())
print(min(-N%K, N%K))
N,K= map(int, input().split())
if N<K:
    print(min(N%K,abs(N%K-K)) )
else:
    print(min(N%K,abs(N%K-K)))
n,k=map(int,input().split())
r=n%k
print(min(r,k-r))
N,K=map(int,input().split())
if N%K != 0:
    if abs(K-N%K)<N:
        print(K-N%K)
    else:
        print(N)
else:
    print(0)
N, K = map(int, input().split())

if N > K:
    if N % K > K / 2:
        print(K - (N % K))
    else:
        print(N % K)
else:
    if N > K / 2:
        print(K - N)
    else:
        print(N)
N, K = map(int, input().split())
cand1 = N % K
cand2 = K - (N % K)
print(min(cand1, cand2))
n,k=map(int,input().split())
x=n%k
print(min(x,k-x))
n, m = map(int, input().split())
print(min(n % m, abs((n % m) - m)))
n,k=map(int,input().split())
while n>k:
  n=n%k
if n>k//2:
  n=abs(n-k)
print(n)
l = list(map(int,input().split()))
s = l[0]%l[1]
if abs(s-l[1])<s:
    print(abs(s-l[1]))
else:
    print(s)
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()

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

if __name__ == "__main__":
    resolve()
str = input().split()
n = int(str[0])
k = int(str[1])
t = n%k
other = abs(k-t)
print(min(t,other))
from sys import stdin, stdout

N, K = map(int,stdin.readline().rstrip().split())

ans = N % K
print(min(ans,abs(ans - K)))
n, k = (int(i) for i in input().split())
flag = True

n = n % k
ans = n

if(ans > abs(n-k)):
    ans = abs(n-k)

print(ans)
N,M=[int(x) for x in input().split()]
print(min(abs(N-N//M*M),abs(N-(N//M+1)*M)))
N,K=list(map(int,input(' ').split(' ')))
print(min(N%K,(-N)%K))
N, K = map(int, input().split())
ans_list = [int(N % K), K - int(N % K)]
print(min(ans_list))
N,K = map(int,input().split())

N %= K
print(min(N,K-N))
n, k = map(int, input().split())
ans = n%k
print(min(ans, abs(ans-k)))
# AtCoder Beginner Contest 161: C (2020/04/04)
N, K = map(int, input().split())
A = abs(N-K*(N//K))
B = abs(N-K*(N//K+1))
if A < B:
    print(A)
else:
    print(B)
N,K = map(int,input().split())
N = N % K
print (min(N,K-N))
n, k = list(map(int, input().split()))

a = n % k
print(min(a, k-a))
N, K = map(int, input().split())
ans =  N % K
if N % K > abs(N%K-K):
    ans = abs(N%K-K)
print(ans)
n, k = map(int, input().split())

print(min(n, n % k, abs((n % k) - k)))
n,m=map(int,input().split())
if(m>n):
    c=m-n
    print(min(c,n))
else:
    if(n%m==0):
        print('0')
    else:
        c=n%m
        print(min(c,m-c))
import sys

N, K = map(int, sys.stdin.readline().strip().split())

r = N // K
print(min((N, N - r*K, (r+1)*K - N)))
n, k = map(int,input().split())
print(min(n%k, abs((n%k)-k)))
n, k = map(int, input().split())
m = n % k
print(min(m, abs(m-k)))
n, k = map(int,input().split())
# print(min(abs(n - k * int(n/k)), abs(n - k * (int(n/k) + 1))))

# もっと簡単に書けばこうか でもなぜ上は通らない？
print(min(n%k, k-(n%k)))
def main():
    import sys
    input = sys.stdin.readline

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


if __name__ == '__main__':
    main()
N, K = map(int, input().split())
if N >= 2*K:
    s = N // K
    print(min(abs(N - s * K), abs(N- (s+1) * K)))
else:
    print(min(abs(N-K), abs(abs(N-K)-K)))
def c_replacing_integer():
    N, K = [int(i) for i in input().split()]
    return min(N % K, K - (N % K))

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

c = n % b

d = abs(c - b)

print(min(c,d))
N, K = map(int, input().split())

N = N % K
if N > abs(N - K):
    print(abs(N - K))
else:
    print(N)
s = list(map(int, input().split()))

N = s[0]
K = s[1]

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

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

N = N % K

if K - N > N:
  print(N)
  exit()
print(K - N)
n,k = map(int, input().split())
amari=n%k
n=min(amari, k-amari)
print(n)
n, k = map(int, input().split())

x = n % k
ans = min(x, abs(k - x))
print(ans)
N, K = map(int, input().split())
A = N // K
B = N % K
if B > abs(B-K):
  print(abs(B-K))
else:
  print(B)
n, k = map(int, input().split())
a = n%k
b = abs(a - k)
print(min(a, b))
N,K = list(map(int,input().split()))

a=N//K

p=abs(N-a*K)
m=abs(N-(a+1)*K)

if p>m:
  print(m)
else:
  print(p)
N,K=list(map(int,input().split()))
print(min(N%K,K-N%K))
a,b=map(int,input().split())
m=a%b
if abs(b-m)<m:
    m=abs(b-m)
print(m)
N, K = map(int, input().split())

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

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

print(min(n%k, abs(n%k-k)))
def listint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
def main(n,k):
    z = n % k
    if z > k-z:
        return k-z
    else:
        return z
n,k = listint()
print(main(n,k))
import math
n,k=map(int,input().split())
num=n//k
n=n-num*k
ans=min(abs(k-n),n)
print(ans)
n,k = map(int,input().split())
if n % k > -(n % k - k):
    print(-(n % k - k))
else:
    print(n % k)
n, k = map(int, input().split())
print(min(n%k, k-n%k))
N, K = map(int,input().split())


N_list = [N,K]

if K == 1:
    print(0)
    
elif N>K:
    print(min(N%K,abs(N%K-K)))
    
elif N == K:
    print(0)
    
else:
    print(min(N,abs(N-K)))
a,b= map(int, input().split())
min = 1000000000000000000000000000000


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

amari = n % k

print(min(amari, abs(amari - k)))
N,K=map(int,input().split())



for i in reversed(range(18)):
    while N > 10 ** i * K:
        N=N-10 ** i * K


while abs(N-K)<N:

    N=abs(N-K)

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

N = N % K
# print(N)
ans_candidate_list = [N]
while True:
    N = abs(N - K)
    # print(N)
    # print(ans_candidate_list)
    if N not in ans_candidate_list:
        ans_candidate_list.append(N)
    else:
        break

print(sorted(ans_candidate_list)[0])
n,k=map(int,input().split())

if k==1:
    print(0)
elif n>k:
    print(k-(n%k))
else:
    val=k-n
    if n<val:
        print(n)
    else:
        print(val)
N,K=map(int,input().split())
a=N%K
b=K/2
 
if a<=b:
    print(a)
else:
    print(K-a)
N, K = map(int, input().split())

x = abs(N -(N//K)*K)
y = abs(N - (N//K + 1)*K)

if x < y:
    print(x)
else:
    print(y)
N, K = map(int, input().split())
if N > K:
  N -= (N//K)*K
ans = N if N <= abs(N-K) else abs(N-K)
print(ans)

# flag = True
# while flag:
#   if N > K:
#     N = abs(N-K)
#   else:
#     ans = N if N <= N -K else N-K
#     flag = False
n,k=map(int, input().split())
n=n%k
n1=abs(n-k)
n2=abs(n1-k)
print(min(n1,n2))
N,K = map(int,input().split())

if N >= K :
    t = N%K
    ans = min(t,K-t)
else:
    ans = min(N,K-N)
    
print(ans)
N, K = map(int, input().split())

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

print(ans)
List = list(map(int, input().split()))

if List[0]%List[1] >= abs(List[0]%List[1] - List[1]):
    print(abs(List[0]%List[1] - List[1]))
else:
    print(abs(List[0]%List[1]))
n,k = map(int,input().split())
n = n % k
if n > k/2 :
    print(k-n)
else:
    print(n)
n, k = map(int, input().split())

ans1 = n % k
ans2 = abs(ans1 - k)

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

n = N%K
print(min(n, abs(n-K)))
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(" "))
Min = N 
while(Min%K<Min):
    Min=Min%K
if abs(Min-K) > Min:
    print(Min)
else:
    print(abs(Min-K))
n,k=map(int,input().split())
r=n%k
s=min([r,k-r])
print(s)
n, k = [int(i) for i in input().split()]
if n % k  == 0:
    print(0)
elif n < k:
    print(min(n, k-n))
else:
    n = n - int(n//k) * k
    n = min(abs(n-k), n)
    n = min(abs(n-k), n)
    print(n)
n, k = map(int, input().split())
rest = n % k
print(min(rest, k - rest))
n,k=map(int,input().split())
amari=n%k
print(min(amari,k-amari))
INF = int(10e20)


def main():
    N, K = tuple([int(_x) for _x in input().split()])

    minval = N
    sub = N // K - 5
    if sub > 0:
        N = N - K * sub

    for i in range(20):
        N = abs(N - K)
        minval = min(N, minval)

    print(minval)


main()
N, K = map(int,input().split())
A = 0
A = N % K
print(min(A, K - A))
n,k = map(int,input().split())


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

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

print(min(n%k, abs(n%k - k)))
a,b=[int(s) for s in input().split()]
print(min([a%b,(b-a)%b]))