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

# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))
ans = {}
a = []
sub = {}
answer = 0
for i in s:
    if not i in a:
        ans[i] = s.count(i)*(s.count(i)-1)//2
        a.append(i)
        sub[i] = (s.count(i)-2)*(s.count(i)-1)//2
        answer += ans[i]
#print(ans)

#print(answer)
for i in range(n):
    print(answer-ans[s[i]]+sub[s[i]])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
List={}
x=0
for i in range(n):
    if not a[i] in List:
        List[a[i]] = 1
    else:
        List[a[i]]+=1
    
sigma=0
 
for key,item in List.items():
    sigma += item*(item-1)//2
for i in range(n):
    print(sigma-List[a[i]]+1)
### BUGGY CODE ###

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

# ps = [0] * (n+1)
# qs = [0] * (n+1)
# ps[-1] = As[-1]
# qs[-1] = As[-1]

p = As[-1]
q = As[-1]
Asr = As[::-1]
qs = [q]
# 深い方から見ていく
for j,a in enumerate(Asr[1:]):
    i = n - (j + 1) 
    p = (p+1)//2 + a 
    q = min(q + a, 2**i)

    # 最小値が、2**iを超えると、深さ0畳めないのでアウト
    if p > 2**i:
        print(-1)
        exit()
    
    # 2**iを超えない範囲での最大値
    qs.append(q)    
    
if p != 1:
    print(-1)
    exit()
qs.reverse()

qs[0] = 1
ans = 1
for i in range(1,n+1):
    if qs[i] > 2**i:
        qs[i] = 2 ** i
    if qs[i] > 2*(qs[i-1]-As[i-1]):
        qs[i] = 2 * (qs[i-1]-As[i-1])
    ans += qs[i]
print(ans)

### FIXED CODE ###

from itertools import accumulate
n = int(input())
As = list(map(int, input().split()))

if n == 0:
    if As[0] == 1:print(1)
    else:print(-1)
    exit()


if As[0] != 0:
    print(-1)
    exit()

b = 1
ans = 1
acc = list(accumulate(As))
s = acc[-1]
for ac,a in zip(acc[1:], As[1:]):
    # print(s-ac,2*b-a)
    b = min(2*b-a, s-ac)
    if b < 0:
        print(-1)
        exit()
    ans += b+a
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((r, d))
    edges[r].append((l, -d))


coord = [None for i in range(n)]
def dfs(v):
    possible = True
    for u, d in edges[v]:
        if not possible:
            break
        if coord[u]:
            if coord[u] != coord[v] + d:
                return False
        else:
            # not visited yet
            coord[u] = coord[v] + d
            possible = possible and dfs(u)

    return possible

ans = True
for i in range(n):
    if coord[i] or not ans:
        continue
    coord[i] = 0
    ans = ans and dfs(i)


if ans:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

from collections import deque

def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for c, v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for c, v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res




n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((d, r))

ts = topological_sort(edges, n)

if len(ts) != n:
    ans = "No"
    # print("Not DAG")
else:
    # DAG
    dist = [-1] * n
    ans = "Yes"
    for i in range(n):
        v = ts[i]
        if dist[v] == -1:
            dist[v] = 0

        for c, u in edges[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + c
            elif dist[u] != dist[v] + c:
                ans = "No"
                break

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

N,K=map(int,input().split())
*A,=map(int,input().split())
A=[1]+A
Ps=[1]*(N+1)

Ps[1]=A[1]
for i in range(2,K+1):
  Ps[i]=Ps[i-1]*A[i]
  
for i in range(K+1,N+1):
  Ps[i] = Ps[i-1]//A[i-K]*A[i]
  if Ps[i-1]<Ps[i]:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

N,K=map(int,input().split())
*A,=map(int,input().split())
A=[1]+A

for i in range(K+1,N+1):
  if A[i-K]<A[i]:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

import math

n = input()
a = input().split()
N = int(n)

ans_list = []
ann = []
for i in range(N):
    ana = 1
    ans = 0
    for j in range(i+1):
        ana = ana * int(a[j])
    ana = ana -1
    for k in range(N):
        ans += int(ana % int(a[k]))
    ans_list.append(ans)

ans_list.sort()
ans_list.reverse()
print(str(ans_list[0]))







### FIXED CODE ###

import math

n = input()
a = input().split()
N = int(n)

ans_list = []
ann = []
ana = 1
for j in range(N):
    ana = ana * int(a[j])
ana = ana -1
ans = 0
for k in range(N):
    ans += int(ana % int(a[k]))
ans_list.append(ans)

ans_list.sort()
ans_list.reverse()
print(str(ans_list[0]))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, a: "List[int]"):

    c = Counter(a)
    kitai = [[[0]*(N+2) for _ in range(N+2)] for _ in range(c[3]+1)]
    kitai[0][0][0] = 0
    for k in range(c[3]+1):
        for j in range(N+1):
            for i in range(N+1):
                if i == 0 and j == 0 and k == 0:
                    continue
                res = N
                if i:
                    res += kitai[k][j][i-1]*i
                if j:
                    res += kitai[k][j-1][i+1]*j
                if k:
                    res += kitai[k-1][j+1][i]*k
                res /= (i+j+k)
                kitai[k][j][i] = res
    print(kitai[c[3]][c[2]][c[1]])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):

    c = [0]*4
    for A in a:
        c[A] += 1

    J = min(c[2]+c[3]+1, N+1)
    I = min(c[1]+c[2]+c[3]+1, N+1)
    kitai = [[[0]*(I+1) for _ in range(J+1)]
             for _ in range(c[3]+1)]
    for k in range(c[3]+1):
        for j in range(J):
            for i in range(I):
                tot = i+j+k
                if tot == 0 or tot > N:
                    continue
                res = N + kitai[k][j][i-1]*i + \
                    kitai[k][j-1][i+1]*j + kitai[k-1][j+1][i]*k
                kitai[k][j][i] = res/tot
    print(kitai[c[3]][c[2]][c[1]])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


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

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

for i in range(1,len(A)+1):
    print(A.count(i))
for i in range(len(A)+1,N+1):
    print(0)

### FIXED CODE ###

import collections

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

c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])
### BUGGY CODE ###

def solve(n):
    res = set()
    for i in range(2, n):
        while n % i == 0:
            res.add(i)
            n /= i
        if(n<=1): break
    res.add(1)
    return res
 
 
A, B = [int(_) for _ in input().split()]
print(len(solve(A) & solve(B)))

### FIXED CODE ###

from math import sqrt


def solve(n):
    res = set()
    for i in range(2, int(sqrt(n))+1):
        while n % i == 0:
            res.add(i)
            n /= i
        if(n<=1): break
    if n>1:
        res.add(n)
    res.add(1)
    return res


A, B = [int(_) for _ in input().split()]
print(len(solve(A) & solve(B)))
### BUGGY CODE ###

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x,m=nii()

ans=x
x_list=[x]
zan=0
for i in range(n-1):
  a=(x**2)%m
  ans+=a
  x=a
  if x in x_list:
    inx=x_list.index(x)
    zan=(n-1)-i-1

    inx=x_list.index(x)+1
    nx_list=x_list[inx:]+[x_list[inx-1]]

    if zan<=len(nx_list):
      ans+=sum(nx_list[:zan])
    else:
      num=zan//len(nx_list)
      q=zan%len(nx_list)
      ans+=sum(nx_list)*num
      ans+=sum(nx_list[:q])
    break
  else:
    x_list.append(x)

print(ans)


### FIXED CODE ###

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x,m=nii()

ans=x
x_list=[x]
zan=0
for i in range(n-1):
  a=(x**2)%m
  ans+=a
  x=a
  if x in x_list:
    inx=x_list.index(x)
    zan=(n-1)-i-1

    inx=x_list.index(x)+1
    nx_list=x_list[inx:]+[x_list[inx-1]]

    if zan<=len(nx_list):
      ans+=sum(nx_list[:zan])
    else:
      num=zan//len(nx_list)
      q=zan%len(nx_list)
      ans+=sum(nx_list)*num
      ans+=sum(nx_list[:q])
    break
  else:
    x_list.append(x)

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

import numpy as np
 
N,Max_W = map(int,input().split())
 
dp = [0 for _ in range(Max_W + 1)]
dp = np.array(dp)
 
for i in range(N):
    w,v = map(int,input().split())
    a = dp[:-w] + v
    b = dp[w:]
    m = np.maximum(a,b)
    dp[w:] = m
print(dp[-1])

### FIXED CODE ###

import numpy as np
 
N,Max_W = map(int,input().split())
INF = np.inf

dp = np.full(N*10**3+1,Max_W+1,dtype=np.int64)
dp[0] = 0
for i in range(N):
    w,v = map(int,input().split())
    a = dp[:-v] + w
    b = dp[v:]
    m = np.minimum(a,b)
    dp[v:] = m
max_w = 0
max_v = 0
ans = np.where( dp <= Max_W )
print(np.max(ans))
### BUGGY CODE ###

n=int(input())
s=[sorted(list(input())) for _ in range(n)]
ans=0

for i in range(n-1):
    for j in range(i+1,n):
        if s[i]==s[j]:
            ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
dic={}
ans=0

for i in s:
    t=dic.get(i,0)
    ans+=t
    dic[i]=t+1

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

N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A=sorted(A)
sumcost = 0
for i in range(M):
    sumcost += A[0][0]
    A[0][1] -= 1
    if A[0][1] < 1:
        A.pop(0)

print(sumcost)

### FIXED CODE ###

N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
for i in range(M):
    sumcost += A[0][0]
    A[0][1] -= 1
    if A[0][1] < 1:
        A.pop(0)

print(sumcost)
### BUGGY CODE ###

N=int(input())
A = list(map(int,input().split()))
B=0
mod=10**9+7
for i in range(N):
 for j in range(i+1,N):
  B+=A[i]^A[j]
  B%=mod
print(B)

### FIXED CODE ###

mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  c=B[j]
  if c[i]=="1":
   d+=1
  else:
   e+=1
 f+=d*e*pow(2,61-i,mod)
 f%=mod
print(f)
### BUGGY CODE ###

import numpy as np
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]

ab = np.array([x[0]-x[1] for x in AB])
sorted_ab = np.array(sorted(ab))
AB = np.array(AB)

Takahashi = 0
Aoki = 0
for i in range(N):
    if i % 2 == 0:
        t = np.where(ab == sorted_ab[0])
        T = np.array([AB[i][0] for i in list(t)[0]])
        T1 = np.where(T == max(T))
        t = list(t)[0][[list(T1)[0][0]][0]]
        Takahashi += AB[t][0]
        ab = np.delete(ab, t)
        sorted_ab = np.delete(sorted_ab, 0)
        AB = np.delete(AB, [t], axis=0)
    else:
        a = np.where(ab == sorted_ab[0])
        A = np.array([AB[i][1] for i in list(a)[0]])
        A1 = np.where(A == max(A))
        a = list(a)[0][[list(A1)[0][0]][0]]
        Aoki += AB[a][1]
        ab = np.delete(ab, a)
        sorted_ab = np.delete(sorted_ab, 0)
        AB = np.delete(AB, [a], axis=0)


print(Takahashi-Aoki)



### FIXED CODE ###

N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]

ab = sorted([x[0]+x[1] for x in AB], reverse=True)
ans = 0
for i in range(N):
    ans -= AB[i][1]

if N % 2 == 0:
    K = N // 2
else:
    K = N // 2 + 1
for i in range(K):
    ans += ab[2*i]


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

S = input()
T = input()
n = len(S)
for i in range(n):
    s = S[i]
    t = T[i]
    S = S.translate(str.maketrans({s: t, t: s}))
if S == T:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

S = input()
T = input()
st = {}
ts = {}
for s, t in zip(S, T):
    if s in st and st[s] != t:
        print("No")
        exit()
    if t in ts and ts[t] != s:
        print("No")
        exit()
    st[s] = t
    ts[t] = s
print("Yes")
### BUGGY CODE ###

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

ans=-1
for i in range(n):
  tmp=0
  for j in range(i+1,n):
    if H[j-1]>=H[j]:
      tmp+=1
    else:
      break
  ans=max(ans,tmp)
  if ans>=len(H[i:]):
    break
print(ans)


### FIXED CODE ###

import itertools
n=int(input())
H=list(map(int,input().split()))

ans=[]
for i in range(1,n):
  if H[i-1]>=H[i]:
    ans.append(1)
  else:
    ans.append(0)

out=0
tmp=0
for a in ans:
  if a==1:
    tmp+=1
  else:
    out=max(out,tmp)
    tmp=0
print(max(out,tmp))
### BUGGY CODE ###

if __name__ == "__main__":
    n, m = map(int, input().split())

    nexts = [[] for i in range(n)]
    
    for i in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    scores = [m] * m
    scores[0] = 0

    red_set = [0]
    new_red_set = []
    blue_set = [x + 1 for x in range(n - 1)]
    new_blue_set = blue_set

    arrows = [0] * n

    while len(blue_set) != 0:
        for r in red_set:
            for nxt in nexts[r]:
                if nxt in blue_set:
                    new_blue_set.remove(nxt)
                    if nxt not in new_red_set:
                        new_red_set.append(nxt)
                    arrows[nxt] = r
                blue_set = new_blue_set

        red_set = new_red_set
        new_red_set = []
    
    print("Yes")
    for arrow in arrows[1:]:
        print(arrow + 1)
    

### FIXED CODE ###

from sys import stdin
from collections import deque
input = stdin.readline


def main():
    n, m = map(int, input().split())

    nexts = [[] for i in range(n)]
    
    for _ in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [-1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues
    checked = [0] * n

    red_deque = deque([0])

    while len(red_deque) > 0:
        rd = red_deque[0]
        red_deque.popleft()
        if checked[rd] == 0:
            checked[rd] = 1
            for nxt in nexts[rd]:
                if blues[nxt] == -1:
                    blues[nxt] = rd
                    red_deque.append(nxt)

    print("Yes")
    for blue in blues[1:]:
        print(blue + 1)
    

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


a,b,c,d = [int(x) for x in input().split()]
ans = -999999999999999
for i in range(a,b+1):
    for j in range(c,d+1):
        ans = max(ans,i*j)
        
print(ans)

### FIXED CODE ###

a,b,c,d = [int(x) for x in input().split()]


print(max(a*c,a*d,b*c,b*d))
### BUGGY CODE ###

N = input()
length = len(N)
jogai = 0
ans = 0

def check(number):
    three = 0
    five = 0
    seven = 0
    for i in range(len(str(number))):
        if str(number)[i:i+1] == '3':
            three += 1
        elif str(number)[i:i+1] == '5':
            five += 1
        elif str(number)[i:i+1] == '7':
            seven += 1
        else:
            return False
    if three >= 1 and five >= 1 and seven >= 1:
        return True
    else:
        return False

if int(N) <= int('7'*length):
    if int(N)%2 == 0:
        for l in range(int(int(N)/2), int(int('7'*length)/2)):
            if check(2*l+1):
                jogai += 1
    elif int(N)%2 == 1:
        for l in range(int((int(N)+1)/2),int(int('7'*length)/2)):
            if check(2*l+1):
                jogai +=1

    

for i in range(1,length+1):
    ans += 3**i-3*2**i+3

print(ans-jogai)

### FIXED CODE ###

n = int(input())

def recursive(s):
    if int(s) > n:
        return 0
    ret = 0
    if s.count('3')>0 and s.count('5')>0 and s.count('7')>0:
        ret = 1
    for c in '753':
        ret += recursive(s+c)
    return ret           

print(recursive('0'))
### BUGGY CODE ###

a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: 100000000000000000000 * (1 + student[0]) + student[1])


maxer = 0
for i in range(len(fanwei)):
    now = -100000000000000000000
    ans = 0
    for i in fanwei[i:]:
        down = i[0]
        if down >= now:
            ans += 1
            now = i[1]
    maxer = max(ans, maxer)

print(maxer)


### FIXED CODE ###

a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: student[0] + 100000000000000000000 * student[1])

now = -100000000000000000000
ans = 0
for i in fanwei[:]:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]


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

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

ans = 0
for i in range(a,b+1):
  ans ^= i
print(ans)

### FIXED CODE ###

import math

def f(n):
  s = ""
  if n <= 0:
    return 0
  for i in reversed(range(int(math.log2(n))+1)):
    if i == 0:
      s += "1" if ((n-1)//2)%2 == 0 else "0"
    else:
      s += "1" if (n//(2**i))%2 + (n+1)%2 == 2 else "0"
  return int(s,2)

a,b = map(int,input().split())
print( f(a-1) ^ f(b) )
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
def CountFrequency(my_list,n1): 
    count1 = 0
    freq = {} 
    for items in my_list: 
        freq[items] = my_list.count(items) 
    for key, value in freq.items():
    	print(value)
    	count1+=1
    if(count1!=n1):
        for i in range(n1-count1):
            print("0")
CountFrequency(a,n)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
arr = [0 for i in range(n)]
for i in range(n-1):
    arr[a[i]-1]+=1
for i in range(n):
    print(arr[i])
### BUGGY CODE ###

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, n = map(int, readline().split())
t = 0
max_t = 0

for i in range(n, 1, -1):
    t = math.floor(a*i/b) - a * math.floor(i/b)
    if t > max_t:
        max_t = t

print(max_t)


### FIXED CODE ###

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = math.floor(a * min(n, b-1) / b)

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

import sys

line = sys.stdin.readline()
x, y = line.split(" ")

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

divide = 1

if x > y:
    x, y = y, x

while(x > 1) :
    for i in range(2, x + 2):
        if  x % i == 0 and y % i == 0:
            divide = divide * i
            x = x / i
            y = y / i
            break

print divide

### FIXED CODE ###

import sys

def div(x, y):
    if x % y == 0:
        print y
    else:
        div(y, x%y)


line = sys.stdin.readline()
x, y = line.split(" ")

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

if x < y:
    x, y = y, x

if x == y:
    print x

else:
    div(x, y)
### BUGGY CODE ###

n,k = map(int,input().split())
ls = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    p = (ls[i]+1)/2
    a.append(p)
for j in range(n+1-k):
    q = sum(a[j:j+k])
    b.append(q)
print(max(b))


### FIXED CODE ###

n,k = map(int,input().split())
ls = list(map(int,input().split()))
l,p = 0,0
for i in range(n):
    if l < k:
        p += (1+ls[i])/2
        l += 1
        continue
    if i == k:
        now = p
    now = now-((1+ls[i-k])/2)+((1+ls[i])/2)
    p = max(p,now)
print(p)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

S = input()
Q = int(input())

for i in range(Q):
    l = list(input().split()) 
    if l[0] == '1':
        S = S[::-1]
    else:
        if l[1] == '1':
            S = l[2] + S
        else:
            S += l[2]
print(S)

### FIXED CODE ###

from collections import deque

S = deque(list(input()))

Q = int(input())

cnt = 0
for i in range(Q):
    l = list(map(str,input().split()))
    if int(l[0]) == 1:
        cnt += 1
    else:
        if int(l[1]) == 1:
            if cnt % 2 == 1:
                S.append(l[2])
            else:
                S.appendleft(l[2])
        else:
            if cnt % 2 == 1:
                S.appendleft(l[2])
            else:
                S.append(l[2])

if cnt % 2 == 1:
    S = list(S)[::-1]
print(''.join(S))
### BUGGY CODE ###

import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if num[0]!=num[1] and all([x%num[1]==0 for x in data[1::]])==False:
    count=int(num[1]/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

### FIXED CODE ###

from fractions import gcd
import numpy as np
n=int(input())
data=list(map(int,input().split()))
left=np.zeros(n+1,dtype=np.int)
right=np.zeros(n+1,dtype=np.int)
kotae=1
for i in range(n):
    left[i+1]=gcd(left[i],data[i])
    right[n-i-1]=gcd(right[n-i],data[n-i-1])
for j in range(n):
    num=gcd(left[j],right[j+1])
    kotae=max(num,kotae)
print(kotae)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1

if n % 2 == 0:
    for i in range(n//2):
        ans *= a[i]
        ans *= a[n-i-1]

if n % 2 == 1:
    for i in range(n//2):
        ans *= a[i]
        ans *= a[n-i-1]

    ans *= a[n//2+1]

if ans > 10**18:
    ans = -1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
if a[0] == 0:
    ans = 0
    print(ans)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()

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

from collections import deque


def main():
    N, Q = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        adj[a-1].add(b-1)
        adj[b-1].add(a-1)
    cnt = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x
    ans = [0] * N
    q = deque([(0, 0, -1)])
    while len(q):
        cur, total, prev = q.popleft()
        total += cnt[cur]
        ans[cur] = total
        for a in adj[cur]:
            if a == prev:
                continue
            q.append((a, total, cur))
    print(*ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        adj[a-1].add(b-1)
        adj[b-1].add(a-1)
    cnt = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x
    ans = [0] * N
    q = deque([(0, 0, -1)])
    while len(q):
        cur, total, prev = q.popleft()
        total += cnt[cur]
        ans[cur] = total
        for a in adj[cur]:
            if a == prev:
                continue
            q.append((a, total, cur))
    print(*ans)


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

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

### FIXED CODE ###

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