Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

d,g=map(int,input().split())
g=g//100
pc=[list(map(int,input().split())) for i in range(d)]
P=0
C=0#合計
for i in range(d):
    pc[i][1]=pc[i][1]//100
    C=(C+pc[i][1]+pc[i][0]*(i+1))
    P+=pc[i][0]
dp=[10000000]*(C+1)
for i in range(d):
    dp_sub=[10000000]*(C+1)
    for j in range(C+1):
        if j==0:
            for k in range(1,pc[i][0]+1):
                if k!=pc[i][0]:
                    dp_sub[k*(i+1)]=k
                else:
                    dp_sub[k*(i+1)+pc[i][1]]=k
        elif dp[j]!=10000000:
            for k in range(1,pc[i][0]+1):
                if k!=pc[i][0]:
                    dp_sub[j+k*(i+1)]=min(dp[j]+k,dp_sub[j+k*(i+1)])
                else:
                    dp_sub[j+k*(i+1)+pc[i][1]]=min(dp[j]+k,dp_sub[j+k*(i+1)+pc[i][1]])

    for j in range(C+1):
        if dp_sub[j]!=0:
            dp[j]=min(dp[j],dp_sub[j])
m=P
for i in range(g,C+1):
    if dp[i]!=0:
        m=min(m,dp[i])
print(m)


### FIXED CODE ###

import math
d,g=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(d)]
ans=10000000000000000000
for i in range(1<<d):
    s=0
    ans_=0
    for j in range(d):
        if (i>>j)&1:
            s+=(pc[j][1]+pc[j][0]*100*(j+1))
            ans_+=pc[j][0]
    #print(s,ans_)
    if s>=g:
        ans=min(ans,ans_)
    else:
        for j in range(d-1,-1,-1):
            if not((i>>j)&1):
                if s+(pc[j][0]*100*(j+1))>=g:
                    h=-((s-g)//(100*(j+1)))
                    s+=(h*100*(j+1))
                    ans_+=h
                    ans=min(ans,ans_)
                    break
                else:
                    break
print(ans)
#ansとans_
#謎のWA
### BUGGY CODE ###

A, B, C = map(int, input().split())
count = 0
while A%2 == 0 and B%2 == 0 and C%2 == 0:
  A, B, C = B//2+C//2, A//2+C//2, A//2+B//2
  count += 1
print(count)
  

### FIXED CODE ###

A, B, C = map(int, input().split())
count = 0

while A%2 == 0 and B%2 == 0 and C%2 == 0:
  if A == B and B == C:
    print(-1)
    exit()
  A, B, C = B//2+C//2, A//2+C//2, A//2+B//2
  count += 1
print(count)
### BUGGY CODE ###

def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A += map(int, input().split())  # 速度のため一次元で管理
    B = []
    for _ in range(H):
        B += map(int, input().split())  # 速度のため一次元で管理

    dp = [0] * (H * W)  # 速度のため一次元で管理,dp[pos]:=bit,[-80*H*W,80*H*W]->[0,2*80*H*W]
    d = abs(A[0] - B[0])
    dp[0] |= 1 << (80 * H * W + d)
    dp[0] |= 1 << (80 * H * W - d)

    for r in range(H):
        for c in range(W):
            p = r * W + c
            d = abs(A[p] - B[p])
            if r > 0:
                dp[p] |= (dp[p - W] << d)
                dp[p] |= (dp[p - W] >> d)
            if c > 0:
                dp[p] |= (dp[p - 1] << d)
                dp[p] |= (dp[p - 1] >> d)

    ans = 2 * 80 * H * W + 1
    for j in range(2 * 80 * H * W + 1):
        if (dp[H * W - 1] >> j) & 1:
            t = j - 80 * H * W
            if ans > abs(t):
                ans = abs(t)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# https://atcoder.jp/contests/abc147/submissions/8871745
# 写経
# bitset 高速化

def main():
    import numpy as np

    H, W = map(int, input().split())
    A = np.array([[int(x) for x in input().split()] for _ in range(H)])
    B = np.array([[int(x) for x in input().split()] for _ in range(H)])
    D = np.abs(A - B)

    MAX_BIAS_PER_CELL = 80
    UPPER_BOUND_TOTAL_BIAS = MAX_BIAS_PER_CELL * (H + W - 1) + 1

    dp = [[0] * W for _ in range(H)]
    dp[0][0] = 1 << UPPER_BOUND_TOTAL_BIAS
    # dp[r][c]:(r,c)で値の加減を行った後、
    # 達成可能なbiasに該当するbitを立てたbit表現
    # 2**UPPER_BOUND_TOTAL_BIASの位をbias=0とみなす

    # -UPPER_BOUND_TOTAL_BIAS, ..., 0, ...UPPER_BOUND_TOTAL_BIAS [意味するbias]
    # 0, ..., UPPER_BOUND_TOTAL_BIAS, ..., UPPER_BOUND_TOTAL_BIAS*2 [dpに代入されるbit表現の桁]

    # numpyのndarrayを使用しなかった理由
    # dtypeでuint64を採用しても、
    # 2**(UPPER_BOUND_TOTAL_BIAS*2)は収まらない
    # pythonのintなら収まる

    for r in range(H):
        for c in range(W):
            x = dp[r][c]
            if r > 0:
                x |= dp[r - 1][c]
            if c > 0:
                x |= dp[r][c - 1]
            # x:(r,c)到達可能なbiasのbit表現

            d = D[r][c]
            dp[r][c] = (x << d) | (x >> d)
            # (r,c)マスでのbias変化を加味したbit表現

    ret = min(
        abs(UPPER_BOUND_TOTAL_BIAS - shift)
        for shift in range(UPPER_BOUND_TOTAL_BIAS * 2)
        if (dp[H - 1][W - 1] & (1 << shift)) > 0)

    print(ret)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()

sum=0
while A:
  if len(A)==1 or A[0]!=A[1]:
    sum+=1
  B=A.copy()
  for j in range(len(A)):
    if A[j]%A[0]==0:
      B.remove(A[j])
  A=B
print(sum)    
  

### FIXED CODE ###

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

A.sort()

dp=[False]*(10**6*2)
ans=0
for idx,i in enumerate(A):
  if dp[i]:continue
  tmp=i
  ans+=1
  while tmp<10**6*2-1:
    dp[tmp]=True
    tmp+=i
  if idx!=len(A)-1 and A[idx+1]==i:
    ans-=1
print(ans)
### BUGGY CODE ###

import copy

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

for i in range(N):
    a = copy.deepcopy(A)
    a.remove(A[i])
    print(max(a))


### FIXED CODE ###

import copy

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

result = max(A)
ind = A.index(result)

for i in range(N):
    if i == ind:
        a = copy.deepcopy(A)
        a.remove(result)
        print(max(a))
    else:
        print(result)
### BUGGY CODE ###

S = list(input())
 
f = True
cnt = 0
while f:
  f = False
  for i in range(len(S)-1):
    if S[i]=='B' and S[i+1]=='W':
      S[i] = 'W'
      S[i+1] = 'B'
      cnt += 1
      f = True
      break
print(cnt)

### FIXED CODE ###

S = input()
W = []
 
for i, s in enumerate(S):
  if s == 'W':
    W.append(i)

idx = 0
ans = 0
for w in W:
  ans += w-idx
  idx += 1

print(ans)
### BUGGY CODE ###

from sys import exit

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

H.sort(reverse=True)

if len(H) <= K:
    print(0)
    exit()

for _ in range(K):
    H.pop(0)

print(sum(H))


### FIXED CODE ###

from sys import exit

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

if len(H) <= K:
    print(0)
    exit()

H.sort(reverse=True)
H = H[K:]

print(sum(H))
### BUGGY CODE ###

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

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

ans_list = []

for i in range(int(b / 10), n + 1):
  #print(int((a * i) / b), a * int(i / b), int((a * i) / b) - a * int(i / b))
  ans = int((a * i) / b) - a * int(i / b)
  ans_list.append(ans)
print(max(ans_list))



### FIXED CODE ###

# -*- coding: utf-8 -*-
# x = p * b + q
# 0 <= q < b
# int(a * p + a * q / b) - a * int(p - q / b)
# = a * p + int(a * q / b) - a * p
# = int(a * q / b)

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

print(a * min(b - 1, n) //  b)
### BUGGY CODE ###

N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        for k in range(N-dj):
            dk=dj+k+1
            a=Ln[di-1]
            b=Ln[dj-1]
            c=Ln[dk-1]
            if((a+b)>c)&((b+c)>a)&((c+a)>b) :
                Ans +=1

print(Ans)


### FIXED CODE ###

N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)
### BUGGY CODE ###

n, k = map(int, input().split())
def func(x):
    return abs(x-k)
ans = n
while min(func(n), n) != n:
    ans = func(n)
    n = func(n)
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
a, b = divmod(n, k)
print(min(abs(n - k*(a+1)), b))
### BUGGY CODE ###

import bisect
N = int(input())

As = sorted(list(map(int, input().split())))
Bs = sorted(list(map(int, input().split())))
Cs = sorted(list(map(int, input().split())))

ans = 0
for c in Cs:
    i = bisect.bisect_left(Bs, c)
    for b in Bs[:i]:
        ans += bisect.bisect_left(As, b)
print(ans)

### FIXED CODE ###

import bisect
N = int(input())

As = sorted(list(map(int, input().split())))
Bs = list(map(int, input().split()))
Cs = sorted(list(map(int, input().split())))

ans = 0
for b in Bs:
    a = bisect.bisect_left(As, b)
    c = bisect.bisect_right(Cs, b)
    ans += a * (N-c)
print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
for _ in range(Q):
    b, c = list(map(int, input().split()))
    A[A==b] = c
    print(np.sum(A))

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
D = np.zeros((10**5)+1)
S = sum(A)
for i in range(len(A)):
    D[A[i]] += 1
Q = int(input())
for _ in range(Q):
    b, c = list(map(int, input().split()))
    S += D[b]*(c-b)
    D[c] += D[b]
    D[b] = 0
    print(int(S))
### BUGGY CODE ###

k, s = map(int, input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                ans += 1
                break

print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            ans += 1

print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(200001)
N, Q = map(int, input().split())
a_b = [list(map(int, input().split())) for _ in range(N-1)]
p_x = [list(map(int, input().split())) for _ in range(Q)]
 
rin = [[] for _ in range(N)]
for v in a_b:
    rin[v[0]-1].append(v[1]-1)
    rin[v[1]-1].append(v[0]-1)
    
score = [0 for _ in range(N)]
for ele in p_x:
    score[ele[0]-1] +=ele[1]
#print(score)
 
def dfs(p, bp=-1):
    for c in rin[p]:
        if c != bp:
            #print(c)
            score[c]+= score[p]
            dfs(c, p)
 
dfs(0)
print(*score)


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(1000000)

n,q = map(int, input().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n-1)]
p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

v = [deque([]) for i in range(n)]
for e in a_b:
    v[e[0]-1]+=[e[1]-1]
    v[e[1]-1]+=[e[0]-1]
score = [0 for i in range(n)]
for e in p_x:
    score[e[0]-1]+=e[1]
def dfs(p, bp=-1):
    while v[p]:
        c =v[p].popleft()
        if c ==bp:
            continue
        #print(p, c, bp)
        score[c]+=score[p]
        dfs(c, bp=p)
visited = [0]                
dfs(0)
print(*score)
### BUGGY CODE ###

def encode(s):
  r = [0]*26
  for n in range(len(s)):
    r[ord(s[n]) - ord('a')] += 1
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

ct = 0
for n in range(N):
  for m in range(n+1,N):
    if S[n]==S[m]:
      ct+=1
      
print(ct)
      
  

### FIXED CODE ###

def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = [0]*N

for n in range(N):
  s = str(input())
  S[n] = encode(s)

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
### BUGGY CODE ###

from collections import Counter

h, w, n = map(int, input().split())
a_list = [[0 for _ in range(w)] for _ in range(h)]
triangle = []
for _ in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for a_i in range(a - 1, a + 2):
        for b_i in range(b - 1, b + 2):
            if (1 <= a_i < h - 1) & (1 <= b_i < w - 1):
                triangle.append(str(a_i) + "_" + str(b_i))
aaa = Counter(list(Counter(triangle).values()))
for i in range(10):
    if i == 0:
        print((h - 2) * (w - 2) -  sum(aaa.values()))
    elif i in aaa.keys():
        print(aaa[i])
    else:
        print(0)



### FIXED CODE ###

from collections import Counter, defaultdict

ans = defaultdict(lambda: 0)
h, w, n = map(int, input().split())
for _ in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for a_i in range(a - 2, a + 1):
        for b_i in range(b - 2, b + 1):
            if (0 <= a_i < h - 2) & (0 <= b_i < w - 2):
                ans[(a_i, b_i)] += 1

k = Counter(ans.values())
print((h - 2) * (w - 2) - sum(k.values()))
for i in range(1, 10):
    if i in k.keys():
        print(k[i])
    else:
        print(0)
### BUGGY CODE ###

# N! 通りの総和は期待値で考えたほうがわかりやすくなることが多そう

import sys
from functools import lru_cache
sys.setrecursionlimit(500000)

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

modinv = make_modinv_list(200)

@lru_cache(maxsize=None)
def solve(idx, X):
    # 降順ソートした S の idx 個目以降を使ったときの操作後の X の期待値
    if idx == N:
        return X
    # idx 個目を idx 個目以降で最初に使うかで場合分け
    res = 0
    # 最初に使う場合（確率 (1/(N-idx))）
    res += modinv[N-idx] * solve(idx+1, X % S[idx]) % mod
    # 最初に使わない場合（確率 ((N-idx-1)/(N-idx))）
    res += (N-idx-1) * modinv[N-idx] * solve(idx+1, X) % mod
    return res % mod

mod = 10**9+7
N, X = map(int, input().split())
S = sorted(map(int, input().split()), reverse=True)
ans = solve(0, X)
for i in range(2, N+1):
    ans = ans * i % mod
print(ans)


### FIXED CODE ###

# N! 通りの総和は期待値で考えたほうがわかりやすくなることが多そう

import sys
from functools import lru_cache
sys.setrecursionlimit(500000)

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

def main():
    modinv = make_modinv_list(200)

    @lru_cache(maxsize=None)
    def solve(idx, X):
        # 降順ソートした S の idx 個目以降を使ったときの操作後の X の期待値
        if idx == N:
            return X
        # idx 個目を idx 個目以降で最初に使うかで場合分け
        res = 0
        # 最初に使う場合（確率 (1/(N-idx))）
        res += modinv[N-idx] * solve(idx+1, X % S[idx]) % mod
        # 最初に使わない場合（確率 ((N-idx-1)/(N-idx))）
        res += (N-idx-1) * modinv[N-idx] * solve(idx+1, X) % mod
        return res % mod

    mod = 10**9+7
    N, X = map(int, input().split())
    S = sorted(map(int, input().split()), reverse=True)
    ans = solve(0, X)
    for i in range(2, N+1):
        ans = ans * i % mod
    print(ans)

main()
### BUGGY CODE ###

N, Q = map(int, input().split())  # 複数数値入力
S = list(input())  # 一文字ずつ格納
L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())  # 複数数値入力
    L.append(l)
    R.append(r)

list = []
flg = 0
for s in S:
    if s == "A" and flg == 0:
        flg = 1
    elif s == "C" and flg == 1:
        list.append(1)
        list.append(2)
        flg = 0
    elif flg == 1:
        list.append(0)
        list.append(0)
    else:
        list.append(0)

for i in range(Q):
    S = list[L[i] - 1:]
    S = S[:R[i] - L[i] + 1]
    if S[0] == 2:
        S = S[1:]
    if S[-1] == 1:
        S = S[:-2]
    print(int(sum(S)/3))


### FIXED CODE ###

import numpy as np

N, Q = map(int, input().split())  # 複数数値入力
S = list(input())  # 一文字ずつ格納

dp = [0] * N
i = 0
flg = False
for str in S:
    if str == "C" and flg == True:
        dp[i] = dp[i - 1] + 1
        flg = False
    elif str == "A":
        flg = True
        dp[i] = dp[i-1]
    else:
        flg = False
        dp[i] = dp[i-1]
    i += 1

for i in range(Q):
    l, r = map(int, input().split())  # 複数数値入力
    print(dp[r-1]-dp[l-1])
### BUGGY CODE ###

def f(x,y):
    if x%y==0:
        return y
    x,y=y,x%y
    return f(x,y)

def main():
    K=int(input())
    sum=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            for c in range(1,K+1):
                sum+=f(a,f(b,c))
    return sum

print(main())

### FIXED CODE ###

def f(x,y):
    if x%y==0:
        return y
    x,y=y,x%y
    return f(x,y)

def main():
    K=int(input())
    sum=0
    for a in range(1,K+1):
        sum+=a
    for a in range(1,K):
        for b in range(a+1,K+1):
            sum+=6*f(a,b)
    for a in range(1,K-1):
        for b in range(a+1,K):
            for c in range(b+1,K+1):
                sum+=f(a,f(b,c))*6
    return sum

print(main())
### BUGGY CODE ###

N,K = map(int,input().split())
from collections import deque

#期待値はΣ(from 1 to pi)/len(pi)
P = [(p+1)/2 for p in map(int,input().split()) ]

que = deque(P[:K])
counter = sum(que)
for k in range(K,N):
    que.popleft()
    que.append(P[k])
    counter = max(counter,sum(que))

print(counter)

### FIXED CODE ###

N,K = map(int,input().split())
#from collections import deque

#期待値はΣ(from 1 to pi)/len(pi)
P = list(map(int,input().split()))
cumsum = [0]*(N+1)
counter = []
for k in range(N):
    cumsum[k+1]=cumsum[k]+P[k]

for i in range(N-K+1):
    counter.append(cumsum[i+K]-cumsum[i])

print((max(counter)+K)/2)
### BUGGY CODE ###

mod = 1000000007
n = int(input())
s = input()
abets ="abcdefghijklmnopqrstuvwxyz"
counts = []
for c in abets:
  counts.append(s.count(c))
ans =-1
for ptn in range(2** len(abets)):
  bin_str = format(ptn,'b')
  subans = 1
  for i, b in enumerate(bin_str[::-1]):
    if b =='1':
      subans = (subans * counts[i]) % mod
  ans = (ans + subans) % mod
print(ans)

### FIXED CODE ###

mod = 1000000007
n = int(input())
s = input()
abets ="abcdefghijklmnopqrstuvwxyz"
counts = []
for c in abets:
  counts.append(s.count(c))
ans = 0
for cnt in counts:
  if cnt != 0:
    ans = (ans + ans*cnt + cnt) % mod
print(ans)
### BUGGY CODE ###


N = int(input())
S = input()

sum = 3000000
for i in range(0, N):
    # print("left", S[:i])
    # print("right", S[i+1:])
    left_side_reverse_num = S[:i].count('W')
    right_side_reverse_num = S[i+1:].count('E')

    # print(left_side_reverse_num)
    # print(right_side_reverse_num)

    if sum > left_side_reverse_num + right_side_reverse_num:
        sum = left_side_reverse_num + right_side_reverse_num

    #print(sum)
print(sum)

### FIXED CODE ###


N = int(input())
S = input()

w_num = S.count('W')
e_num = S.count('E')

rev_num = S[1:].count('E')
rev_num_list = [rev_num]

for i in range(1, N):
    add = 0
    if S[i-1] == 'W':
        add +=1
    if S[i] == 'E':
        add -=1
    rev_num_list.append(rev_num_list[i-1] + add)

print(min(rev_num_list))
### BUGGY CODE ###

S = input()
N = len(S)

ans = 0
cnt = [0] * 2019
s=""

for i in range(N)[::-1]:
    s = S[i] + s
    cnt[int(s) % 2019] += 1

ans += cnt[0]
for i in range(1, 2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)


### FIXED CODE ###

S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

ans += cnt[0]
for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
### BUGGY CODE ###

N = int(input())
rabit = [ int(v) for v in input().split(" ") ]
skip = []
num = 0

for i in range(N):
  n = rabit[i]
  if i in skip:
    continue
  if rabit[n-1] == i+1:
    skip.append(n-1)
    num += 1

print(num)

### FIXED CODE ###

N = int(input())
rabit = input().split(" ")
skip = []
num = 0

for i in range(N):
  n = int(rabit[i])
  if n < i+1:
    continue
  if int(rabit[n-1]) == i+1:
    num += 1

print(num)
### BUGGY CODE ###

import sys
n,k=map(int,input().split())
if n%k==0:
    print(0)
    sys.exit()
while abs(n-k)<n:
    n=abs(n-k)
    
    if n==0:
        print(n)
        sys.exit()
else:
    print(n)

### FIXED CODE ###

import sys
n,k=map(int,input().split())
if n%k==0:
    print(0)
    sys.exit()
if n%k<abs(k-n%k):
    print(n%k)
else:
    print(abs(k-n%k))
### BUGGY CODE ###

R, G ,B, N = map(int, input().split())

tmp = [R, G, B]
tmp.sort()
R, G, B = tmp[2], tmp[1], tmp[0]


num_R = N // R + 1
num_G = N // G
RG = [[N - R*i for i in range(num_R)]]

for j in range(num_G):
    RG.append([RG[-1][i] - G for i in range(num_R)])

check = lambda x: 0 if x < 0 else 1 if x == 0 else 1 if x%B == 0 else 0

a = []
count = 0
for i in range(len(RG)):
    a = list(map(check, RG[i]))
    count += sum(a)

print(count)


### FIXED CODE ###

R, G, B, N = map(int, input().split())

count = 0
for i in range(N // R + 1):
    n = N - R * i
    for j in range(n // G + 1):
        if (n - G*j) >= 0 and (n - G*j) % B == 0:
            count += 1

print(count)
### BUGGY CODE ###

N = int(input())
M = 18
left = 0
right = N-1
print(left)
l = input()
if l != "Vacant":
  print(right)
  r = input()
  if r != "Vacant":
    notOK = True
    while notOK:
      middle = (r+l)//2
      print(middle)
      s = input()
      if s == "Vacant":
        notOK = False
        break
      elif (middle-left)%2 == 0 and l != s:
        right = middle
        r = s
      elif (middle-left)%2 == 1 and l == s:
        right = middle
        r = s
      elif (right-middle)%2 == 0 and s != r:
        left=middle
        l = s
      elif (right-middle)%2 == 1 and r == s:
        left = middle
        r = s


### FIXED CODE ###

N = int(input())
M = 18
left = 0
right = N-1
print(left)
l = input()
if l != "Vacant":
  print(right)
  r = input()
  if r != "Vacant":
    notOK = True
    while notOK:
      middle = (right+left)//2
      print(middle)
      s = input()
      if s == "Vacant":
        notOK = False
        break
      elif (middle-left)%2 == 0 and l != s:
        right = middle
        r = s
      elif (middle-left)%2 == 1 and l == s:
        right = middle
        r = s
      else:
        left=middle
        l = s
### BUGGY CODE ###

def main():
    a,b = map(int,input().split())
    s = a
    for i in range(a+1,b+1):
        s = s ^ i
    print(s)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    a,b = map(int,input().split())
    def f(n):
        if n%4==0:
            return n
        if n%4==1:
            return 1
        if n%4==2:
            return n + 1
        if n%4==3:
            return 0
    print(f(b)^f(a-1))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
s = list(input())

count = 0
while len(s)>1 :
    if s[0] == s[1]:
        s.pop(0)
    else:
        s.pop(0)
        count += 1

print(count+1)

### FIXED CODE ###

n = int(input())
s = list(input())

count = 0
while len(s)>1 :
    if s[0] == s[1]:
        s.pop(0)
    else:
        s.pop(0)
        count += 1

print(count+1)
### BUGGY CODE ###

import numpy as np
s = input()
q = int(input())
sgn = 1
for i in range(q):
    qi = np.array(input().split(),dtype=str)
    if qi[0] == "1":
        sgn *= -1
    else:
        if (qi[1] == "1" or sgn == -1) and (qi[1] == "2" or sgn == 1):
            s = qi[2] + s
        else:
            s = s + qi[2]

if sgn == 1:
    print(s)
else:
    news = ''.join(list(reversed(s)))
    print(news)


### FIXED CODE ###

import numpy as np
s = input()
q = int(input())
rbef = []
aft = []
sgn = 1
for i in range(q):
    qi = np.array(input().split(),dtype=str)
    if qi[0] == "1":
        sgn *= -1
    else:
        if (qi[1] == "1" or sgn == -1) and (qi[1] == "2" or sgn == 1):
            rbef.append(qi[2])
        else:
            aft.append(qi[2])

bef = "".join(reversed(rbef))
taft = "".join(aft)
ans = bef + s + taft

if sgn == 1:
    print(ans)
else:
    rans = ''.join(list(reversed(ans)))
    print(rans)
### BUGGY CODE ###

l, r = map(int, input().split())
ans = (l*r)%2019
for i in range(l, r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)
    if ans == 0:
        print(ans)
        exit()
print(ans)


### FIXED CODE ###

l, r = map(int, input().split())
ans = (l*r)%2019
for i in range(l, r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)
        if ans == 0:
            print(ans)
            exit()
print(ans)