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

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

p = [i for i in a if i >= 0]
n = [i for i in a if i < 0]

process = []
if len(p) > 0 and len(n) > 0:
    p_seed = p.pop(0)
    n_seed = n.pop(0)
    while len(n) > 0:
        sub = n.pop(0)
        process.append((p_seed, sub))
        p_seed -= sub
    while len(p) > 0:
        sub = p.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
elif len(p) > 0:
    p.sort(reverse=True)
    p_seed = p.pop(0)
    n_seed = p.pop(-1)
    while len(p) > 0:
        sub = p.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
else:
    n.sort(reverse=True)
    p_seed = n.pop(0)
    n_seed = n.pop(-1)
    while len(n) > 0:
        sub = n.pop(0)
        process.append((n_seed, sub))
        p_seed -= sub
    process.append((p_seed, n_seed))
m = p_seed - n_seed
print(m)
for x, y in process:
    print(str(x) + ' ' + str(y))


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split(' ')))
a.sort(reverse=True)

process = []
p_seed = a.pop(0)
n_seed = a.pop(-1)
for e in a:
    if e >= 0:
        process.append((n_seed, e))
        n_seed -= e
    else:
        process.append((p_seed, e))
        p_seed -= e
process.append((p_seed, n_seed))
m = p_seed - n_seed
print(m)
for x, y in process:
    print(str(x) + ' ' + str(y))
### BUGGY CODE ###

N = int(input())
A = [int(a) for a in input().split()]

A_set = list(set(A))
ans = 0
for i in range(len(A_set)):
  nm = A_set[i]
  nm_cnt = A.count(nm)
  if nm > N:
    ans += nm_cnt
    continue
  
  if nm_cnt < nm:
    ans += nm_cnt
  elif nm_cnt > nm:
    ans += nm_cnt - nm
  N -= nm_cnt

print(ans)

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]

ans = 0
C = [0] * N # [1の個数, 2の個数, 3の個数, ... , Nの個数]
for i in range(N):
  n = A[i]
  if n <= N:
    C[n-1] += 1
  else: # n > N:
    ans += 1

for i in range(N):
  cnt = C[i]
  if cnt > i+1:
    ans += (cnt - (i+1))
  elif cnt < i+1:
    ans += cnt

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

k,s = map(int,input().split())
#x + y + z = s z < k
counter = 0
for i in range(k + 1):
    for j in range(k + 1):
        for l in range(k + 1):
            if i + j + l > s:
                break
            if l > k:
                break
            if i + j + l == s:
                #print(i,j,l)
                counter += 1

print(counter)


### FIXED CODE ###

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

print(counter)
### BUGGY CODE ###

a, b, x = list(map(int, input().split()))
ans = 0
for i in range(a, b+1):
    if i % x == 0:
        ans += 1
print(ans)

### FIXED CODE ###

a, b, x = list(map(int, input().split()))
b_ans = b//x
amin_ans = (a-1)//x
ans = b_ans-amin_ans
print(ans)
### BUGGY CODE ###

def fun(x):
    ret = 1
    while x:
        ret *= x
        x -= 1
    return ret

def cmb(n,r):
    if n==r: return 1
    if n<r: return 0
    else: return fun(n) // (fun(r)*fun(n-r))




n = int(input())

ss = ["".join(sorted(input())) for i in range(n)]
ss.sort()

tmp = ss[0]
sss = [0]*n
j = 0
for i in range(n):
    if tmp == ss[i]: sss[j]+=1
    else:
        tmp = ss[i]
        j += 1
        sss[j]+=1

ans = 0
for i in sss:
    if i: ans += cmb(i,2)
print(ans)

### FIXED CODE ###

n = int(input())
d = {}

for i in range(n):
    s = "".join(sorted(input()))
    if s in d: d[s] += 1
    else: d[s] = 1
ans = 0
for i in d.values():
    ans += (i*i-i)//2
print(ans)
### BUGGY CODE ###

import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])

que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = max([len(i) for i in tree])
color = [[i for i in range(1,maxi+1)] for _ in range(N+1)]
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        
        
        if edge[i[1]] == -1:
            col = max(color[i[0]][0],color[start][0])
            edge[i[1]] = col
            que.put(i[0])
            color[i[0]].remove(col)
            color[start].remove(col)
print(maxi)
for i in edge[1:]:
    print(i)

### FIXED CODE ###

import queue 
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
    a,b = map(int,input().split())
    tree[a].append( [b,i])
    tree[b].append([a,i])
 
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
start = 0
color = [[] for _ in range(N+1)]
node[1] = 0
while(True):
    if que.empty():
        break
    before = start
    start = que.get()
    col =1
    for i in tree[start]:
        
        if node[i[0]] == -1 :
            que.put(i[0])
        if edge[i[1]] == -1:
            if col == node[start]:
                col += 1
            edge[i[1]] = col
            node[i[0]] = col
            if col > maxi:
                maxi = col
            col +=1
            
print(maxi)
for i in edge[1:]:
    print(i)
### BUGGY CODE ###

from itertools import permutations
N, W, R = map(int, input().split())
S = list(map(int, input().split()))

INFTY = 10**9
cost = [[INFTY]*(N+1) for _ in range(N+1)]

# 辺を入力
for _ in range(W):
    u, v, c = map(int, input().split())
    cost[u][v] = c
    cost[v][u] = c

# 自身に向かうコストは0
for i in range(N+1):
    cost[i][i] = 0


def WarshallFloyd():
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])


WarshallFloyd()

ans = 10**9
for T in permutations(S, R):
    temp = 0
    t = T[0]
    for i in range(1, R):
        temp += cost[t][T[i]]
        t = T[i]
    ans = min(ans, temp)
print(ans)


### FIXED CODE ###

from itertools import permutations
N, W, R = map(int, input().split())
S = list(map(int, input().split()))

INFTY = 10**9
cost = [[INFTY]*(N+1) for _ in range(N+1)]

# 辺を入力
for _ in range(W):
    u, v, c = map(int, input().split())
    cost[u][v] = c
    cost[v][u] = c

# 自身に向かうコストは0
for i in range(N+1):
    cost[i][i] = 0


def WarshallFloyd():
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])


WarshallFloyd()

ans = 10**9
for T in permutations(S, R):
    temp = 0
    t = T[0]
    for i in range(1, R):
        temp += cost[t][T[i]]
        t = T[i]
    ans = min(ans, temp)
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

MOD=2019
l,r=map(int,input().split()) #l<=i<i+1<=j<=r
res=[]

if r - l > 2019:
  print(0)
  
else:
  l=l%MOD
  r=r%MOD
  l,r=min(l,r),max(l,r)

  for i in range(l,r):
    for j in range(i+1,r+1):
      res += [(i*j)%MOD]

  print(min(res))
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]

flag = False
mem = []
ind = 0
while not flag:
  if a[ind] in mem:
    break

  if a[ind] == 2:
    flag = True
    break
    
  mem.append(a[ind])    
  ind = a[ind] - 1
  
print(len(mem)+1 if flag else -1)
  

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]

flag = False
ind = 1
for cnt in range(n):
  ind = a[ind-1]

  if ind == 2:
    flag = True
    break

print(cnt+1 if flag else -1)
### BUGGY CODE ###

#nn
L, R = map(int, input().split())
mod = 2019

if R - L >= mod:
  print(0)
else:
  s = []
  for i in range(L, R):
    for j in range(i+1, R+1):
      s.append((i*j) % mod)
    s.sort()
  print(s[0])

### FIXED CODE ###

#nn
L, R = map(int, input().split())
mod = 2019

if R - L >= mod:
  print(0)
else:
  s = []
  for i in range(L, R):
    for j in range(i+1, R+1):
      s.append((i*j) % mod)
  s.sort()
  print(s[0])
### BUGGY CODE ###

if __name__ == '__main__':
    n, x, y = map(int, input().split())
    x, y = x - 1, y - 1
    k = [0] * (n - 1)
    for i in range(n):
        tmp = 0
        for j in range(i):
            if i == j:
                continue
            t = min(abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j))
            k[t - 1] += 1
    for i in k:
        print(i)


### FIXED CODE ###

if __name__ == '__main__':
    n, x, y = map(int, input().split())
    x, y = x - 1, y - 1
    k = [0] * (n - 1)
    for i in range(n):
        tmp = 0
        for j in range(i):
            if i == j:
                continue
            t = min(abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j))
            k[t - 1] += 1
    for i in k:
        print(i)
### BUGGY CODE ###

n=int(input())
s=str(input())

def isThere(suji):
    flag1=False
    flag2=False
    flag3=False
    for i in s:
        if flag2==True and suji[2]==i:
            flag3=True
            break
        if flag1==True and suji[1]==i:
            flag2=True
        if suji[0]==i:
            flag1=True
    return flag3 

candidate=list(range(1000))
candidate=['0'+'0'+str(candidate[i]) if candidate[i]<10 else ('0'+str(candidate[i]) if 9<candidate[i]<100 else str(candidate[i])) for i in range(1000)]
ans=0
for suji in candidate:
    if isThere(suji):
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
s=str(input())
 
def isThere(suji):
    flag1=False
    flag2=False
    flag3=False
    for i in s:
        if flag2==True and suji[2]==i:
            flag3=True
            break
        if flag1==True and suji[1]==i:
            flag2=True
        if suji[0]==i:
            flag1=True
    return flag3 
 
candidate=list(range(1000))
candidate=['0'+'0'+str(candidate[i]) if candidate[i]<10 else ('0'+str(candidate[i]) if 9<candidate[i]<100 else str(candidate[i])) for i in range(1000)]
ans=0
for suji in candidate:
    if isThere(suji):
        ans+=1
print(ans)
### BUGGY CODE ###

n,x,y=map(int,input().split())
lst=[]
for i in range(1,n):
  for j in range(i+1,n+1):
    lst.append(min(abs(i-j),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x)))
for i in range(1,n):
  print(lst.count(i))

### FIXED CODE ###

import collections
n,x,y=map(int,input().split())
lst=[]
num=[0]*(n+1)
for i in range(1,n):
  for j in range(i+1,n+1):
    k=min(abs(i-j),abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x))
    if num[k]==0:
      num[k]+=1
    lst.append(k)
    
Lst=list(collections.Counter(lst).items())
key=0
for i in range(1,n):
  if num[i]==0:
    print(0)
  else:
    print(Lst[key][1])
    key+=1
### BUGGY CODE ###

count = int(input())
list = [int(x) for x in input().split()]
b = 1
for a in list:
    b *= a

threshold = int(1000000000000000000)

if b > threshold:
    print('-1')
else:
    print(b)

### FIXED CODE ###

def main ():
  count = int(input())
  c = list(map(int,input().split()))

  if 0 in c:
    print(0)
    return

  result = 1
  for a in c:
    result *= a
    if result > 1000000000000000000:
      print(-1)
      return

  print(result)

main()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
set_a=set(a)
count=0
for i in set_a:
    if i<a.count(i):
        count+=a.count(i)-i
    if a.count(i)<i:
        count+=a.count(i)
print(count)


### FIXED CODE ###

from collections import Counter
n=int(input())
counter=Counter(map(int,input().split()))
sum=0
for a,cnt in counter.items():
    if cnt<a:
        sum+=cnt
    else:
        sum+=cnt-a
print(sum)
### BUGGY CODE ###

n=int(input())
ans=1
a=list(map(int,input().split()))
m=n-a.count(1)
for i in range(n):
    ans*=a[i]
    if 0 in a:
        ans=0
        break
    if m>70:
        ans=-1
        break
    if ans>1000000000000000000:
        ans=-1
        break
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
flag=0
ans=0
if 0 in a:
    flag=1
if flag==0:
    ans=1
    for i in range(n):
        ans*=a[i]
        if ans>1000000000000000000:
            flag=-1
            break
if flag==-1:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

N,Q = (int(i) for i in input().split())
X = []
for i in range(N-1):
    Y = [int(n) for n in input().split()]
    X.append(Y)
X = sorted(X, key=lambda x:x[1])
Z = [] 
for i in range(N):
    Z.append(0)
    
for i in range(Q):
    Z_1,Z_2 = (int(i) for i in input().split())
    Z[Z_1-1] = Z[Z_1-1] + Z_2

#print(X)
#print(Z)

ans=[]
for i in range(N):
    ans.append(0)
ans[0]=Z[0]

for i in range(1,N):
    ans[i] += Z[i]
    for n in range(len(X)):
        if X[n][1] == i+1:
            ans[i] += ans[X[n][0]-1]
            A = n+1
        else:
            for i in range(A):
                X.pop(0)
            break

#print(ans)
print(' '.join(map(str, ans)))

### FIXED CODE ###

N,Q = (int(i) for i in input().split())
X = []
for i in range(N-1):
    Y = [int(n) for n in input().split()]
    X.append(Y)
X = sorted(X, key=lambda x:x[1])
Z = []
for i in range(N):
    Z.append(0)
    
for i in range(Q):
    Z_1,Z_2 = (int(i) for i in input().split())
    Z[Z_1-1] = Z[Z_1-1] + Z_2

#print(X)
#print(Z)


ans=[Z[0]]

for i in range(1,N):
    ans.append(Z[i])
    ans[i] += ans[X[i-1][0]-1]
    
#print(ans)
print(' '.join(map(str, ans)))
### BUGGY CODE ###

s = list(input())
n = int(input())
sl = []
fl = []
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if q[1] == "1":
            if flag:
                sl.insert(0, q[2])
            else:
                fl.append(q[2])
        else:
            if flag:
                fl.append(q[2])
            else:
                sl.insert(0, q[2])
if flag:
    s = sl+s
    s = s+fl
else:
    sl.reverse()
    fl.reverse()
    s.reverse()
    s = fl+s
    s = s+sl
print("".join(s))

### FIXED CODE ###

from collections import deque
s = deque(list(input()))
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if (q[1] == "1" and flag == False) or (q[1] == "2" and flag):
            s.append(q[2])
        else:
            s.appendleft(q[2])
if flag == False:
    s.reverse()
print("".join(s))
### BUGGY CODE ###

MOD=10**9+7

N,M=map(int,input().split())
slist=list(map(int,input().split()))
tlist=list(map(int,input().split()))

dp,dp_sum=[],[]
for i in range(N+1):
  dp.append([0]*(M+1))
  dp_sum.append([1]*(M+1))
dp[0][0]=1
#print(dp)

for i in range(1,N+1):
  for j in range(1,M+1):
    if slist[i-1]==tlist[j-1]:
      dp[i][j]=dp_sum[i-1][j-1]      
    dp_sum[i][j]=(dp[i][j]+dp_sum[i-1][j]+dp_sum[i][j-1]-dp_sum[i-1][j-1])%MOD
#print(dp)
#print(dp_sum)

print(dp_sum[-1][-1])

### FIXED CODE ###

MOD=10**9+7

N,M=map(int,input().split())
slist=list(map(int,input().split()))
tlist=list(map(int,input().split()))

dp,dp_sum=[],[]
for i in range(N+1):
  dp.append([0]*(M+1))
  dp_sum.append([1]*(M+1))
dp[0][0]=1
#print(dp)

for i in range(1,N+1):
  for j in range(1,M+1):
    if slist[i-1]==tlist[j-1]:
      dp[i][j]=dp_sum[i-1][j-1]      
    dp_sum[i][j]=(dp[i][j]+dp_sum[i-1][j]+dp_sum[i][j-1]-dp_sum[i-1][j-1])%MOD
#print(dp)
#print(dp_sum)

print(dp_sum[-1][-1])
### BUGGY CODE ###

n = int(input())
nums = [int(x) for x in input().split()]
total = 0

for i in range(0,n-1):
    for j in range(i+1,n):
        #print(nums[i],nums[j])
        total += (nums[i]*nums[j])

print(total%(10**9+7))

### FIXED CODE ###

n = int(input())
nums = [int(x) for x in input().split()]
multinums = [0]
total = 0

for i in range(0,n):  #累積和配列を作成する
    multinums.append(multinums[i]+nums[i])

#print(multinums)

for i in range(0,n):
    #print(nums[i],multinums[n]-multinums[i+1],nums[i] * (multinums[n]-multinums[i+1]))
    total += nums[i] * (multinums[n]-multinums[i+1])

print(total%(10**9+7))
### BUGGY CODE ###

n = int(input()) #1行目のNを取得する
list = [input() for i in range(n)] #複数行の数値の入力を取得
lint = [int(s) for s in list]

ans = max(lint)
index = [i for i, x in enumerate(lint) if x == max(lint)]

if len(index) >= 2:
    for i in range(n):
        print(ans)
elif len(index) == 1:
    for i in range(0, index[0], 1):
        print(ans)
    a = lint.pop(index[0])
    print(max(lint))
    lint.append(a)
    for i in range(index[0] + 1, n, 1):
        print(ans)

### FIXED CODE ###

n = int(input()) #1行目のNを取得する
list = [input() for i in range(n)] #複数行の数値の入力を取得
lint = [int(s) for s in list]

ans = max(lint)
index = lint.index(max(lint))
lint.remove(max(lint))
ans2 = max(lint)

if ans == ans2:
    for i in range(n):
        print(ans)
else:
    for i in range(0, index):
        print(ans)
    print(ans2)
    for i in range(index+1, n):
        print(ans)
### BUGGY CODE ###

from itertools import product
from random import randint

def sol():
    N = int(input())
    XYP = [tuple(map(int, input().split())) for _ in range(N)]
    XYP.sort(key=lambda xyp: xyp[2], reverse=randint(0, 1))

    X = [x for x, _, _ in XYP]
    Y = [y for _, y, _ in XYP]
    INF = 10**18

    def calcCost(AP, A):
        ret = [[INF] * N for _ in range(1 << N)]
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i, (a, p) in enumerate(AP):
                cost = abs(a)
                for z in useA:
                    cost = min(cost, abs(a - z))
                ret[state][i] = cost * p
        return ret

    costX = calcCost([(x, p) for x, _, p in XYP], X)
    costY = calcCost([(y, p) for _, y, p in XYP], Y)

    ans = [INF] * (N + 1)
    for state in product((0, 1, 2), repeat=N):
        stateX = 0
        stateY = 0
        M = N
        for s in state:
            stateX <<= 1
            stateY <<= 1
            if s == 0: M -= 1
            if s == 1: stateX |= 1
            if s == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
            if cost >= ans[M]:
                break
        else:
            ans[M] = cost

    print(*ans, sep='\n')

sol()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

a,b,c=map(int,input().split())
n = a // (b+c)
m = a - (b+c)*n
res = n*b
for i in range(m):
  if i < b:
    res += 1
print(res)

### FIXED CODE ###

a,b,c=map(int,input().split())
n = a // (b+c)
m = a - (b+c)*n
res = n*b
if m < b:
  res += m
else:
  res += b
print(res)
### BUGGY CODE ###

def main():
  import sys
  from heapq import heappush, heappop, heapify
  _int = int
  _min = min
  n = _int(input())
  a = [_int(e) for e in input().split()]
  b = [_int(e) for e in input().split()]
  result = 0
  finished = 0
  hq = [(-b[i], i) for i in range(n)]
  heapify(hq)
  while True:
    _, i = heappop(hq)
    if a[i] == b[i]:
      finished += 1
      continue
    if i == 0:
      j = b[n - 1] + b[1]
    elif i == n - 1:
      j = b[n - 2] + b[0]
    else:
      j = b[i - 1] + b[i + 1]
    if len(hq) != 0:
      k = _min(b[i] + hq[0][0], b[i] - a[i]) // j
    else:
      k = (b[i] - a[i]) // j
    if k <= 0:
      k = 1
    b[i] -= j * k
    if a[i] > b[i]:
      print(-1)
      sys.exit()
    result += k
    if a[i] == b[i]:
      finished += 1
      if finished == n:
        print(result)
        sys.exit()
    else:
      heappush(hq, (-b[i], i))
main()

### FIXED CODE ###

def main():
  import sys
  _int = int
  n = _int(input())
  a = [_int(e) for e in input().split()]
  b = [_int(e) for e in input().split()]
  result = 0
  q = [i for i in range(n) if b[i] != a[i]]
  while len(q) != 0:
    nq = []
    c = 0
    for i in q:
      if i == 0 or i == n - 1:
        j = b[(n + i - 1) % n] + b[(n + i + 1) % n]
      else:
        j = b[i - 1] + b[i + 1]
      if j > b[i] - a[i]:
        nq.append(i)
        continue
      c += 1
      k = (b[i] - a[i]) // j
      result += k
      b[i] -= j * k
      if a[i] != b[i]:
        nq.append(i)
    if c == 0 and len(nq) != 0:
      print(-1)
      sys.exit()
    q = nq
  print(result)
main()
### BUGGY CODE ###

n = int(input())
s = [input() for x in range(n)]
length = 10
count = 0

for i in range(n):
    s1 = list(s[i])
    s1.sort()
    for j in range(i+1,n):
        flag = True
        s2 = list(s[j])
        s2.sort()
        for k in range(length):
            if (s1[k] == s2[k]):
                continue
            else:
                flag = False
                break
        if (flag):
            count += 1

print(count)


### FIXED CODE ###

n = int(input())
s = [input() for x in range(n)]
count = 0
d = {}

for i in range(n):
    s1 = list(s[i])
    s1.sort()
    string = "".join(s1)
    if (string not in d.keys()):
        d[string] = 0
    else:
        d[string] += 1
        count += d[string]

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

from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, bisect_left(L,L[a]+L[b])):
            if L[c]>=L[a]+L[b]:
                break
            else:
                cnt += 1
print(cnt)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        cnt += bisect_left(L,L[a]+L[b])-(b+1)
print(cnt)
### BUGGY CODE ###

n = int(input())
number = list(map(int, input().split()))
seki = 1
seki2 = -1
for i in number:
  seki = seki*i
if seki > 10 ** 18:
  print(seki2)
else:
  print(seki)


### FIXED CODE ###

n = int(input())
number = list(map(int, input().split()))
seki = 1
if 0 in number:
  seki = 0
else:
  for i in number:
    seki = seki*i
    if seki > 10 ** 18:
      seki = -1
      break
    else:
      continue
print(seki)
### BUGGY CODE ###

n, k = map(int, input().split())
a_l = list(map(int, input().split()))
base = list(set(a_l))
num = len(base)-k
ans = [n] * len(base)

if num <= 0:
    print(0)
else:
    for idx, v in enumerate(base):
        ans[idx] = a_l.count(v)
    print(sum(sorted(ans)[:num]))

### FIXED CODE ###

n, k = map(int, input().split())
a_l = sorted(list(map(int, input().split())))
base = list(set(a_l))
num = len(base)-k
ans = []

if num <= 0:
    print(0)
else:
    c_idx = 1
    c_num = a_l[0]
    for idx, v in enumerate(a_l[1:]):
        if c_num == v:
            c_idx += 1
            continue
        else:
            ans.append(c_idx)
            c_idx = 1
            c_num = v
    ans.append(c_idx)

    print(sum(sorted(ans)[:num]))