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

n = int(input())
table = [[] for _ in range(n+1)]
for i in range(1, n+1):
  a = list(map(int, input().split()))
  table[i] = a
cursor = [0]*(n+1)
is_matched = set()
d = 0
match = 0
while match < n * (n-1) //2:
  now_match = match
  for i in range(1, n):
    if cursor[i] < n-1 and i not in is_matched:
      j = table[i][cursor[i]]
      if i < j and j not in is_matched and table[j][cursor[j]] == i :
        match += 1
        cursor[i] += 1
        is_matched.add(i)
        cursor[j] += 1
        is_matched.add(j)
  if now_match == match:
    print(-1)
    exit()
  if d > 100000:
    print(499500)
    exit()  
  d += 1
  is_matched.clear()
print(d)

### FIXED CODE ###

n = int(input())
table = [[] for _ in range(n+1)]
for i in range(1, n+1):
  a = list(map(int, input().split()))
  table[i] = a
cursor = [0]*(n+1)
is_matched = set()
d = 0
match = 0
while match < n * (n-1) //2:
  now_match = match
  for i in range(1, n):
    if cursor[i] < n-1 and i not in is_matched:
      j = table[i][cursor[i]]
      if i < j and j not in is_matched and table[j][cursor[j]] == i :
        match += 1
        cursor[i] += 1
        is_matched.add(i)
        cursor[j] += 1
        is_matched.add(j)
  if now_match == match:
    print(-1)
    exit()
  if d > 30000:
    print(499500)
    exit()  
  d += 1
  is_matched.clear()
print(d)
### BUGGY CODE ###

from math import factorial
MOD = 10 ** 9 + 7

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
time = (X+Y) // 3
diff = X - Y
if abs(diff) > time:
    print(0)
    exit()
x_time = (time+diff) // 2
res = 1
for i in range(1,time+1):
    res = res*i%MOD
for i in range(1,x_time+1):
    res = res*mod_inv(i,MOD)%MOD
for i in range(1,time-x_time+1):
    res = res*mod_inv(i, MOD)%MOD
print(res)
#print(mod_combination(time, x_time, MOD))


### FIXED CODE ###

import numpy as np
from math import factorial
MOD = 10 ** 9 + 7

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv



U = 10**6
fact, fact_inv = make_fact(U,MOD)

X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
time = (X+Y) // 3
diff = X - Y
if abs(diff) > time:
    print(0)
    exit()
x_time = (time+diff) // 2

answer = fact[time] * fact_inv[x_time] % MOD * fact_inv[time-x_time] % MOD
print(answer)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,k = LI()
    a = sorted(LI())
    sa = sum(a)
    if sa < k:
        return n
    if sa - a[0] < k:
        return 0

    mi = 0
    ma = n-1

    def f(m):
        am = a[m]
        if am >= k:
            return True

        t = [False] * (k-am)
        t[0] = True
        tl = len(t)
        for i in range(n):
            if i==m:
                continue
            ai = a[i]
            for j in range(tl-1,-1,-1):
                if not t[j]:
                    continue
                if k <= j+ai:
                    continue
                if j+ai >= tl:
                    return True

                t[j+ai] = True

        return False

    while mi < ma:
        m = (mi+ma) // 2
        if f(m):
            ma = m
        else:
            mi = m+1

    return mi


print(main())


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,k = LI()
    a = sorted(LI())
    sa = sum(a)
    if sa < k:
        return n
    if sa - a[0] < k:
        return 0

    mi = 0
    ma = n-1

    def f(m):
        am = a[m]
        if am >= k:
            return True

        t = [False] * (k-am)
        t[0] = True
        tl = len(t)
        for i in range(n):
            if i==m:
                continue
            ai = a[i]
            for j in range(tl-1,-1,-1):
                if not t[j]:
                    continue
                if k <= j+ai:
                    continue
                if j+ai >= tl:
                    return True

                t[j+ai] = True

        return False

    while mi < ma:
        m = (mi+ma) // 2
        if f(m):
            ma = m
        else:
            mi = m+1

    return mi


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

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 2019
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

S = input()
N = len(S)

d = defaultdict(int)
d[0] += 1
cnt = 0
# nums = [0]*(N+1)
last = 0
for i in range(N):
    m = 10**(N-i-1)%MOD
    # val = (int(S[i])*m + nums[i])%MOD
    val = (int(S[i])*m + last)%MOD
    last = val
    cnt += d[val]
    d[val] += 1
print(cnt)

### FIXED CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 2019
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

S = input()
N = len(S)

d = defaultdict(int)
d[0] += 1
# nums = [0]*(N+1)
m = 0
last = 0
dd = 1
for i in range(N):
    m += int(S[N-i-1])*dd
    m %= MOD
    # val = (int(S[i])*m + nums[i])%MOD
    # cnt += d[val]
    dd = (dd*10)%MOD
    d[m] += 1

cnt = 0
for i, v in d.items():
    cnt += v*(v-1)//2
print(cnt)
### BUGGY CODE ###

s = input()
q = int(input())
flg = False
for i in range(q):
    query = input()
    if query[0] == '1': flg = not flg
    else:
        t,f,c = query.split()
        if flg:
            s = c+s if f=='2' else s+c
        else:
            s = c+s if f=='1' else s+c
if flg: s = ''.join(list(reversed(s)))
print(s)

### FIXED CODE ###

from collections import deque

t = input()
s = deque()
for i in range(len(t)): s.append(t[i])
q = int(input())
flg = False
for i in range(q):
    query = input()
    if query[0] == '1': flg = not flg
    else:
        t,f,c = query.split()
        if flg:
            s.appendleft(c) if f=='2' else s.append(c)
        else:
            s.appendleft(c) if f=='1' else s.append(c)
if flg: s = reversed(s)
print(''.join(s))
### BUGGY CODE ###

a=[1]+[0]*4
for s in input():
 i=ord(s)-64
 if i>0:a[i]+=a[i-1]
 else:a=[a[i]*3+a[i-1]for i in range(4)]+[0]
print(a[3]%(10**9+7))

### FIXED CODE ###

def index(c):return ord(c)-ord('A')+1
s=' '+input()
m=10**9+7
dp=[[0]*4 for _ in range(len(s))]
dp[0][0]=1
for i in range(1,len(s)):
    for j in range(4):
        dp[i][j]=dp[i-1][j]
    if s[i]=='?':
        dp[i][0]=dp[i-1][0]*3%m
        for j in range(1,4):
            dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]*3)%m
    else:
        k=index(s[i])
        dp[i][k]=(dp[i-1][k-1]+dp[i-1][k])%m
print(dp[-1][3])
### BUGGY CODE ###

def findProductSum(A,n):
    product = 0
    for i in range (n):
        for j in range (i+1,n):
            product += A[i]*A[j]
    return product

N = int(input())
a = list(map(int,input().split()))
print(findProductSum(a,N)%(10**9+7))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ans = 0
mod = 10**9+7

for i in range(n-1):
    s -= a[i]
    ans += a[i]*s

print(ans%mod)
### BUGGY CODE ###

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

B = {A[0]:A.count(A[0])}
for i in range(1,len(A)):
    B[A[i]] = A.count(A[i])

num = len(B)
C = list(B.values())
C.sort()
ans = 0
if num>K:
    ans = sum(C[0:num-K])
print(ans)


### FIXED CODE ###

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

B = [0]*N
for i in range(N):
    B[A[i]-1]+=1

B.sort()

print(sum(B[0:N-K]))
### BUGGY CODE ###

N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
dp = [0]*(1+W)
w,v = WV[0]
dp[w:] = [v]*(W+1-w)
for i in range(1,N):
    w,v = WV[i]
    for j in range(W, w-1, -1):
        tmp = dp[j-w] + v
        dp[j] = max(dp[j], tmp)
print(max(dp))

### FIXED CODE ###

N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
dp = [0]*(1+W)
w,v = WV[0]
dp[w:] = [v]*(W+1-w)
for i in range(1,N):
    w,v = WV[i]
    for j in range(W, w-1, -1):
        tmp = dp[j-w] + v
        dp[j] = max(dp[j], tmp)
print(max(dp))
### BUGGY CODE ###

import numpy as np

q = int(input())
lr = []
for i in range(q):
    li, ri = map(int, input().split())
    lr.append([li, ri])

range_max = 100000
tf = np.ones(range_max, dtype=int)
tf[0] = 0

i = 1
while True:
    if i == int(range_max**(1/2))+1:
        break
    if not tf[i]:
        i += 1
        continue

    tmp = np.arange(i, range_max, i+1)
    tf[tmp[1:]] = 0
    i += 1


for i in range(q):
    tmp_index = np.arange(lr[i][0]-1, lr[i][1], 2)
    tmp_1 = tf[tmp_index]
    tmp_2 = tf[(lr[i][0]+1)//2-1:(lr[i][1]+1)//2]
    res = sum(tmp_1 * tmp_2)
    print(res)

### FIXED CODE ###

import numpy as np

q = int(input())
lr = []
for i in range(q):
    li, ri = map(int, input().split())
    lr.append([li, ri])

range_max = 100000
tf = np.ones(range_max, dtype=int)
tf[0] = 0

i = 1
while True:
    if i == int(range_max ** (1 / 2)) + 1:
        break
    if not tf[i]:
        i += 1
        continue

    tmp = np.arange(i, range_max, i + 1)
    tf[tmp[1:]] = 0
    i += 1

counter = 0
counter_list = [0]
for i in range(2, 100000, 2):
    if tf[i] == 1 and tf[i//2] == 1:
        counter += 1
    counter_list.append(counter)

for i in range(q):
    left = lr[i][0]//2
    right = lr[i][1]//2
    res = counter_list[right] - counter_list[left]
    if left > 0 and counter_list[left] - counter_list[left-1] == 1:
        res += 1
    print(res)
### BUGGY CODE ###

n = int(input())
l = [list(input()) for i in range(n)]
l = ["".join(sorted(i)) for i in l]
l.sort()
s = 0
for i in range(n-1):
  for j in range(i+1,n):
    if l[i] == l[j]:
      s += 1
print(s)


### FIXED CODE ###

import collections
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
l = collections.Counter(s)
ans = sum(i*(i-1)//2 for i in l.values())
print(ans)
### BUGGY CODE ###

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

value = 1
for i in range(N):
  value *= A[i]

if value > 10e+17:
  print('-1')
else:
  print(value)

### FIXED CODE ###

def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main ()
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = input()

    cnt_init = X.count("1")
    x_init = int(X, 2)
    for i in range(n):
        if X[i] == "0":
            cnt = cnt_init + 1
            x = (x_init + pow(2, (n - i - 1), cnt)) % cnt
            res = 1
        else:
            cnt = cnt_init - 1
            if cnt != 0:
                x = (x_init - pow(2, (n - i - 1), cnt)) % cnt
                res = 1
            else:
                x = 0
                res = 0

        while x:
            cnt = bin(x).count("1")
            x %= cnt
            res += 1
        print(res)


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = input()
    cnt_init = X.count("1")
    x = int(X, 2)
    a = x % (cnt_init + 1)
    if cnt_init - 1 != 0:
        b = x % (cnt_init - 1)

    for i in range(n):
        if X[i] == "0":
            cnt = cnt_init + 1
            y = (a + pow(2, n - i - 1, cnt)) % cnt
        else:
            cnt = cnt_init - 1
            if cnt == 0:
                print(0)
                continue
            y = (b - pow(2, n - i - 1, cnt)) % cnt

        res = 1
        while y:
            cnt = bin(y).count("1")
            y %= cnt
            res += 1
        print(res)


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

import sys
n = int(input())
a = input()
q = int(input())
for i in range(q):
  b = list(input().split())
  a = a.replace(b[0],b[1])
  print(sum(list(map(int,a.split()))))

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int,sys.stdin.readline().split()))
q = int(input())
s = sum(a)
cnt = [0]*(10**5+5)
for c in a:
  cnt[c] +=1
for i in range(q):
  b,c = map(int,sys.stdin.readline().split())
  bdif = c-b
  s += cnt[b]*bdif
  cnt[c] += cnt[b]
  cnt[b] = 0
  print(s)
### BUGGY CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))
array = {}
ans = 0

for i in set(A):
    array[i] = A.count(i)

sort_array = sorted(array.items(), key=lambda x: x[1])


if len(sort_array) > k:
    num = len(sort_array) - k
    for i in range(num):
        ans += sort_array[i][1]

print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))
array = {}
ans = 0

for a in A:
    if a in array.keys():
        array[a] += 1
    else:
        array[a] = 1

array = sorted(array.values())

if len(set(A)) > k:
    num = len(array) - k
    for i in range(num):
        ans += array[i]

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

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

sum = 0

for i in range(n-1):
    for j in range(i+1, n):
      sum += a[i]*a[j]
      
print(sum%(10**9+7))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
# required function 
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum)
mod = 10**9+7
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
  
print(modinv(2)*int(findProductSum(a, n))%mod)
### BUGGY CODE ###

from collections import deque
import bisect

N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
cnt2 = 1
for _ in range(M):
  i = As[-1-cnt]  
  i = i//(2**cnt2)
  if i < As[-1-cnt-1]:
    cnt += 1
    cnt2 = 1
    bisect.insort_left(As,i)
  else:
    cnt2 += 1

print(sum(As[:-cnt]))

### FIXED CODE ###

import heapq
 
N, M = map(int, input().split(" "))
As = [-i for i in map(int, input().split(" "))]
As.sort()
heapq.heapify(As)

for _ in range(M):
  i = - heapq.heappop(As)
  i = i >> 1
  heapq.heappush(As,-i)

print(-sum(As))
### BUGGY CODE ###

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

INF = 10**20
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, K):
        if i - k >= 0:
            dp[i + 1] = min(dp[i + 1], dp[i - k] + abs(H[i + 1] - H[i  - k]))

print(dp[N-1])

### FIXED CODE ###

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

INF = 10**9
dp = [INF] * N
dp[0] = 0

for i in range(0, N - 1):
    for k in range(0, min(i + 1, K)):
        if dp[i + 1] > dp[i - k] + abs(H[i + 1] - H[i - k]):
            dp[i + 1] = dp[i - k] + abs(H[i + 1] - H[i - k])


print(dp[N - 1])
### BUGGY CODE ###

N = int(input())
As = sorted(map(int, input().split()))

flgs = [True] * N
for i in range(N):
    if flgs[i]:
        for j in range(i+1, N):
            if As[j] == As[i]:
                flgs[i] = False
                flgs[j] = False
            elif As[j] % As[i] == 0:
                flgs[j] = False

print(flgs.count(True))


### FIXED CODE ###

import numpy as np

N = int(input())
As = sorted(map(int, input().split()))

flgs = np.full(10**6+1, False)
flgs[As] = True

for i, A in enumerate(As):
    if flgs[A] == True:
        flgs[::A] = False
        if i+1 == len(As) or As[i+1] != A:
            flgs[A] = True

print(np.count_nonzero(flgs))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    if N==0:
        if A[0] == 1:
            print(1)
        else:
            print(-1) 
        return 
    
    prev = 0
    leafs = 0
    ans = 0
    for i, a in enumerate(A):
        leafs = leafs*2 + a
        rem = pow(2,i) - leafs
        k = min(rem,sum(A[i+1:]))
        # print(A[i+1:])
        # print(k)
        ans+=k
    # print(leafs)

    rem = pow(2,N) - leafs
    
    if rem<0:
        print(-1)
        return
    print(ans+sum(A))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 - 0 + 1)]  # 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]"):
    if N==0:
        if A[0] == 1:
            print(1)
        else:
            print(-1) 
        return 
    
    s = [0]*(N+1)
    s[N] = A[N]
    for i in range(N-1, -1, -1):
        s[i] = s[i+1] + A[i] 

    leafs = 0
    ans = 0
    for i, a in enumerate(A):
        leafs = leafs*2 + a
        rem = pow(2,i) - leafs
        if i<N:
            # print(sum(A[i+1:]), s[i+1])
            k = min(rem, s[i+1])
            ans+=k
    # print(leafs)

    rem = pow(2,N) - leafs    
    if rem<0:
        print(-1)
        return
    print(ans+sum(A))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 - 0 + 1)]  # type: "List[int]"
    solve(N, A)

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

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

def s(n):
    return n * (n + 1) / 2

def get_expect(i, p):
    return 1.0 * s(p) / p

tl = []
for i in range(N - K + 1):
    t = sum([
        get_expect(i + j, p)
        for j, p in enumerate(P[i:i + K])
    ])

    tl.append(t)

print(max(tl))



### FIXED CODE ###

import numpy as np
from scipy import signal

def main():
    N, K = map(int, input().split(" "))
    P = np.array(list(map(int, input().split(" "))))

    e = (P + 1) / 2

    t = np.ones((K))

    print(np.amax(
        signal.fftconvolve(
            e,
            t
        )
    ))

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

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

A = []
for i in range(Q):
    A.append(input())

points = [K] * N
for correct in A:
    for i in range(N):
        if i != int(correct) - 1:
            points[i] -= 1

for p in points:
    if p > 0:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

answer_count = [0] * N
for i in range(Q):
    answer_count[int(input())-1] += 1

for a in answer_count:
    if K - (Q - a) > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N = int(input())
Nmax = 10**6+1

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

prime = [0]*Nmax
for i in range(N):
    if prime[A[i]] == 0:
        prime[A[i]] = 1
    else:
        prime[A[i]] = -1

for a in A:
    if prime[a] != 0:
        for q in range(a*2, Nmax, a):
            prime[q] = 0



print(sum(a for a in prime if a == 1))

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())

    A = list(map(int, input().split()))
    A. sort()
    Nmax = A[-1] + 1

    prime = [0]*Nmax
    for i in range(N):
        if prime[A[i]] == 0:
            prime[A[i]] = 1
        else:
            prime[A[i]] = -1

    for a in A:
        if prime[a] != 0:
            for q in range(a*2, Nmax, a):
                prime[q] = 0

    res = 0
    for a in prime:
        if a == 1:
            res += 1

    print(res)

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

n = int(input())
a = [int(i) for i in input().split()]
cnt = 1
for ai in a:
  cnt *= ai
if cnt > 10 ** 18:
  print(-1)
else:
  print(cnt)

### FIXED CODE ###

n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = 1
for ai in a:
  cnt *= ai
  if cnt > 10 ** 18:
    print(-1)
    exit()
print(cnt)
### BUGGY CODE ###

N = int(input())
all_list = input().split(' ')

before_list = []

for i in range(N):
  if before_list.count(all_list[i]) == 0:
    before_list.append(all_list[i])
  else:
    print('NO')
    exit()
if len(all_list) == len(before_list):
  print('YES')
  

### FIXED CODE ###

N = int(input())

#listで囲むと良い
A = list(map(int, input().split()))

#setは重複する値が消される
if len(set(A)) == N:
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

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

def get_prime(p):
  result = []
  if p==1:
    return result
  else:
    integers = [1 for _ in range(p+1)]
    integers[0] = 0
    integers[1] = 0
    for i in range(p+1):
      if integers[i] == 1:
        result.append(i)
        for j in range(i,p+1,i):
          integers[j] = 0
    return result

def one_coprime(p):
  count = 0
  for a in A:
    if a%p == 0:
      count += 1
  return count <= 1

def none_coprime(p):
  count = 0
  for a in A:
    if a%p != 0:
      return False
  return True

maxA = max(A)
minA = min(A)

answer = 'pairwise coprime'
if maxA > 1:
  for p in get_prime(maxA):
    if one_coprime(p) == False:
      answer = 'setwise coprime'
      break
if answer == 'setwise coprime' and minA > 1:
  for p in get_prime(minA):
    if none_coprime(p) == True:
      answer = 'not coprime'
      break

print(answer)

### FIXED CODE ###

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

def get_count(p):
  integers = [1 for _ in range(p+1)]
  integers[0] = 0
  integers[1] = 0
  counts = [0 for _ in range(p+1)]
  for a in A:
    counts[a] += 1
  answer = 0
  for i in range(p+1):
    if integers[i] >= 1:
      count = 0
      for j in range(i,p+1,i):
        count += counts[j]
        integers[j] = 0
      answer = max(answer,count)
  return answer

count = get_count(max(A))
if count == N:
  answer = 'not coprime'
elif count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)
### BUGGY CODE ###

data = input().split()
n,k = int(data[0]),int(data[1])


while True:
    if n >= k:
        n -= k
    elif n < k - n:
        break
    else:
        n = k - n
print(n)

### FIXED CODE ###

data = input().split()
n,k = int(data[0]),int(data[1])
print(min(n%k,k-n%k))