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

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

id = [0]*N
Lock = [-1]*N
ans = 0
flag = [True]*N
while(min(id) < N-1):
    ans += 1
    if ans > N**2:
        break

    tmp = set()
    for i in range(N):
        if id[i] >= N-1:
            continue
        else:
            if Lock[i] >= 0:
                continue
            else:
                if Lock[A[i][id[i]]-1] == i and i not in tmp:
                    Lock[A[i][id[i]]-1] = -1
                    id[A[i][id[i]]-1] += 1
                    tmp.add(A[i][id[i]]-1)
                    id[i] += 1
                else:
                    if i not in tmp:
                        Lock[i] = A[i][id[i]]-1
if ans > N**2:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

def main():
    import sys
    import time
    input = sys.stdin.buffer.readline
    start = time.time()
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    M = (N*(N-1)) // 2

    while(min_id < N-1):
        now = time.time()
        if now - start > 1.9:
            ans = M
            break
        ans += 1
        if ans > M:
            break
        tmp = set()
        for i in range(N):
            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > M:
        print(-1)
    else:
        print(ans)


main()
### BUGGY CODE ###

def valid():
    s = input()
    if s=='Vacant': exit()
    return 1 if s=='Male' else 0

n = int(input())
print(0, flush=True)
s_l = valid()
lidx = 0
ridx = n

while True:
    midx = (l+r)//2
    print(midx, flush=True)
    s_m = valid()
    if ((midx-lidx)%2==1) ^ (s_l==s_m):
        lidx = midx
        sl = sm
    else:
        ridx = midx

### FIXED CODE ###

import sys
def valid():
    s = input()
    if s=='Vacant':
        sys.exit()
    return 1 if s=='Male' else 0

n = int(input())
print(0, flush=True)
s_l = valid()
lidx = 0
ridx = n

while True:
    midx = (lidx+ridx)//2
    print(midx, flush=True)
    s_m = valid()
    if ((midx-lidx)%2==1) ^ (s_l==s_m):
        lidx = midx
        s_l = s_m
    else:
        ridx = midx
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        add = (A[i]*A[j]) % mod
        sum = sum + add
        sum = sum % mod
print(sum)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
sum_A = (sum(A)**2) % mod
B = list(map(lambda x: (x**2)% mod,A))
sum_B = sum(B) % mod
print(((sum_A-sum_B)*500000004)%mod)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
n = 2**N
dp = [[float('inf') for i in range(n)] for j in range(M+1)]
for i in range(M+1): dp[i][0] = 0

for i in range(1, M+1):
    a, b = list(map(int, input().split()))
    t = 0

    for c in list(map(int, input().split())):
        t += 2**(c-1)

    for j in range(n): dp[i][j] = dp[i-1][j]
    for j in range(n):
        dp[i][j | t] = min(dp[i][j | t], dp[i-1][j | t], dp[i-1][j]+a)

ans = dp[-1][-1]
if ans == float('inf'): print(-1)
else: print(ans)

### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    INF = float('inf')
    
    L = 2 ** N
    dp = [INF] * L
    dp_next = [INF] * L
    
    nums = [2 ** i for i in range(N)]
    
    for i in range(M):
        a, b = map(int, input().split())
        b = sum([nums[c-1] for c in list(map(int, input().split()))])            
    
        dp[b] = min(dp[b], a)
        for j in range(L):
            n = j | b
            dp_next[n] = min(dp[n], dp_next[n], dp[j]+a)
        
        for j in range(L):
            dp[j] = dp_next[j]
            
    if dp[-1] == INF: print(-1)
    else: print(dp[-1])

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

N,K = map(int, input().split())
h = []
for i in range(N):
  tmp = int(input())
  h.append(tmp)
h.sort()

ans = h[N-1]
for i in range(0, N-K+1):
  tmp = max(h[i:i+K]) - min(h[i:i+K])
  ans = min(ans, tmp)
print(ans)

### FIXED CODE ###

N,K = map(int, input().split())
h = []
for i in range(N):
  tmp = int(input())
  h.append(tmp)
h.sort()

ans = h[N-1]
for i in range(0, N-K+1):
  tmp = h[i+K-1] - h[i]
  ans = min(ans, tmp)
print(ans)
### BUGGY CODE ###

#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
A = [i for i in range(1,N+1)]
B = [0 for i in range(N-1)]
for i in range(N-1):
    B[i] = A[i+1]
B.append(A[0])
sum = 0
for i in range(N):
    sum += (i+1)%B[i]
print(sum)

### FIXED CODE ###

#インポート
import sys
 
#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()
 
N = II()
sum = N*(1+N)//2
print(sum-N)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
for i in range(int(M/N), 0, -1):
  if M % i == 0 and M >= i * N:
    print(i)
    exit()

### FIXED CODE ###

N, M = list(map(int, input().split()))
# 範囲を絞る時は，反対の値も見るべき(M/iのこと)
print(max([j for i in range(int(M**0.5), 0, -1) for j in [i, int(M/i)] if M % j == 0 and M / N >= j]))
### BUGGY CODE ###

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

    sum_a = sum(a)
    min_diff = float('inf')
    for i in range(1,N):
        if min_diff > abs(sum_a-2 * sum(a[i:])):
            min_diff = abs(sum_a-2 * sum(a[i:]))

    print(min_diff)

main()

### FIXED CODE ###

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

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in range(N-1):
        sum_first += a[i]
        if min_diff > abs(sum_a - 2 * sum_first):
            min_diff = abs(sum_a - 2 * sum_first)

    print(min_diff)

main()
### BUGGY CODE ###

N, Q = [int(nq) for nq in input().split()]
AB = []
for i in range(N):
  AB.append([])
for i in range(N - 1):
  a, b = [int(ab) for ab in input().split()]
  AB[a - 1].append(b)
  AB[b - 1].append(a)

P, X = [], []
for j in range(Q):
  p, x = [int(px) for px in input().split()]
  P.append(p)
  X.append(x)

Score = [0] * N
for j in range(Q):
  Score[P[j] - 1] += X[j]

Now = [1]
cnt = 1
while cnt < N:
  for nw in Now:
    for nxt in AB[nw - 1]:
      Score[nxt - 1] += Score[nw - 1]
      AB[nxt - 1].remove(nw)
      Now.append(nxt)
      cnt += 1
    Now.remove(nw)

print(*Score)

### FIXED CODE ###

N, Q = [int(nq) for nq in input().split()]
AB = []
for i in range(N):
  AB.append([])
for i in range(N - 1):
  a, b = [int(ab) for ab in input().split()]
  AB[a - 1].append(b)
  AB[b - 1].append(a)

P, X = [], []
for j in range(Q):
  p, x = [int(px) for px in input().split()]
  P.append(p)
  X.append(x)

Score = [0] * N
for j in range(Q):
  Score[P[j] - 1] += X[j]

Exists = [0] * N

Now = []
Next = [1]
Exists[1 - 1] = 1

while Next != []:
  Now = Next
  Next = []
  for nw in Now:
    for nxt in AB[nw - 1]:
      if Exists[nxt - 1] == 0:
        Exists[nxt - 1] = 1
        Score[nxt - 1] += Score[nw - 1]
        Next.append(nxt)

print(*Score)
### BUGGY CODE ###

A, B = map(int, input().split())
target_list = input().split()

def check_list(lis):
    # print(lis)
    return len(list(set(target_list))) == 1

count = 0
while check_list(target_list) == False:
    min_in_list = min(target_list)
    tmp = A - 1 
    while((target_list[tmp] != min_in_list) or (target_list[tmp] == target_list[tmp-1])):
        tmp -= 1
    min_pos = tmp
    if(min_pos - B) >= 0:
        for i in range(min_pos-(B-1), min_pos):
            target_list[i] = min_in_list
    else:
        for i in range(0, min_pos+1):
            target_list[i] = min_in_list
        for i in range(A-(B-min_pos-1), A):
            target_list[i] = min_in_list

    count += 1

print(count)



### FIXED CODE ###

import math
i, j = map(int, input().split())
target_list = list(map(int, input().split()))
print(math.ceil((i-1)/(j-1)))
### BUGGY CODE ###

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
dp = [0 for i in range(n+1)]
a.sort()
for i in range(1,n+1):
        if i in a:
                a.pop(0)
                dp[i] = 0
                continue
        if i == 1:
                dp[i] = 1
                continue
        if i == 2:
                if dp[i-1] == 0:
                        dp[i] = 1
                else:
                        dp[i] = 2
                continue
        if dp[i-1] == 0:
                dp[i] = dp[i-2]
                continue
        if dp[i-2] == 0:
                dp[i] = dp[i-1]
                continue
        dp[i] = (dp[i-1]+dp[i-2])%(10**9+7)
        #print (dp[i])
print (dp[-1]%(10**9+7))

### FIXED CODE ###

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
dp = [10**5 for i in range(n+1)]
for i in a:
        dp[i] = 0

a.sort()
for i in range(1,n+1):
        if dp[i] == 0:
                continue
        if i == 1:
                dp[i] = 1
                continue
        if i == 2:
                if dp[i-1] == 0:
                        dp[i] = 1
                else:
                        dp[i] = 2
                continue
        if dp[i-1] == 0:
                dp[i] = dp[i-2]
                continue
        if dp[i-2] == 0:
                dp[i] = dp[i-1]
                continue
        dp[i] = (dp[i-1]+dp[i-2])%(10**9+7)
        #print (dp[i])
print (dp[-1]%(10**9+7))
### BUGGY CODE ###

K = int(input())

if K % 2 == 0:
    print(-1)
else:
    n = 7
    i = 1
    while 1:
        if n % K == 0:
            break
        n = (n * 10 + 7) % K
        i += 1
    print(i)

### FIXED CODE ###

K = int(input())

cycle = set()
if K % 2 == 0:
    print(-1)
else:
    n = 7
    i = 1
    while 1:
        if n in cycle:
            i = -1
            break
        if n % K == 0:
            break
        cycle.add(n)
        n = (n * 10 + 7) % K
        i += 1
       
    print(i)
### BUGGY CODE ###

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

def AC_counter(l, r):
    tmp = S[l-1:r]
    print(tmp.count('AC'))

for _ in range(Q):
    l, r = map(int, input().split())
    AC_counter(l, r)


### FIXED CODE ###

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

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)

n, u, v = [int(i) for i in sys.stdin.readline().split()]
u -= 1
v -= 1
graph = {i : [] for i in range(n)}
for i in range(n-1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

distance = 0
stack = [(u, 0)]
already = set()
parent = [i for i in range(n)]
while len(stack) > 0:
    cur, dis = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next in already:
            continue
        parent[_next] = cur
        if _next == v:
            distance = dis + 1
            break
        stack.append((_next, dis + 1))
cur = v
path = []
while cur != u:
    path.append(cur)
    cur = parent[cur]

path_dict = {j : i for i, j in enumerate(path)}
already = set()

def dfs(ind, cur_dis):
    res = 0
    already.add(ind)
    for _next in graph[ind]:
        parent[_next] = ind
        if _next in already:
            continue
        if _next in path:
            if path_dict[_next] <= cur_dis:
                continue
            else:
                res = max(res, dfs(_next, cur_dis + 1) - 1)
        else:
            res = max(res, dfs(_next, cur_dis + 1) + 1)
    return res

res = dfs(u, 0)
if res == 0:
    print(distance - 1)
else:
    print(distance + res - 1)

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)

n, u, v = [int(i) for i in sys.stdin.readline().split()]
u -= 1
v -= 1
graph = {i: [] for i in range(n)}
for i in range(n - 1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

distance = 0
stack = [(u, 0)]
already = set()
parent = [i for i in range(n)]
while len(stack) > 0:
    cur, dis = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next in already:
            continue
        parent[_next] = cur
        if _next == v:
            distance = dis + 1
            break
        stack.append((_next, dis + 1))
cur = v
path = []
while cur != u:
    path.append(cur)
    cur = parent[cur]

path_dict = {j: i for i, j in enumerate(path)}
already = set()
ls = []
stack = [(u, 0, 0)]
while len(stack) > 0:
    ind, cur_dis, minus = stack.pop(-1)
    already.add(ind)
    ls.append(cur_dis - minus)
    for _next in graph[ind]:
        parent[_next] = ind
        if _next in already:
            continue
        if _next in path:
            if path_dict[_next] <= cur_dis + 1:
                continue
            else:
                stack.append((_next, cur_dis + 1, minus + 2))
        else:
            stack.append((_next, cur_dis + 1, minus))

res = max(ls)

if res == 0:
    print(distance - 1)
else:
    print(distance + res - 1)
### BUGGY CODE ###

import sys,math,copy
input = sys.stdin.readline
S = input().strip()
N = len(S)

dp = [[0] * 13 for _ in range(N+1)]
dp[0] = [1] * 13
if S[0] == '?':
    for d in range(10):
        dp[1][(d * 10 ** (N-1)) % 13] = 1
else:
    dp[1][(int(S[0]) * 10 ** (N-1)) % 13] = 1

for n, s in enumerate(S[1:], start=2):
    if s == '?':
        for d in range(10):
            m = (d * 10 ** (N-n)) % 13
            for pm in range(13):
                dp[n][(pm+m)%13] += dp[n-1][pm]
    else:
        m = (int(s) * 10 ** (N-n)) % 13
        for pm in range(13):
            dp[n][(pm+m)%13] += dp[n-1][pm]

print(dp[-1][5] % (10 ** 9 + 7))

### FIXED CODE ###

import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

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

# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, Ma, Mb = inpl()
INF = 4001

DP = [[INF]*(411) for _ in range(411)]
DP[0][0] = 0

for _ in range(N):
    DP2 = [[INF]*(411) for _ in range(411)]
    a, b, c = inpl()
    for i in range(400):
        for j in range(400):
            DP2[i][j] = min(DP[i][j], DP2[i][j])
            DP2[i+a][j+b] = min(DP[i+a][j+b], DP[i][j] + c)
    DP = DP2

x = 1
ans = INF
while Ma*x <= 400 and Mb*x <= 400:
    ans = min(ans, DP[Ma*x][Mb*x])
    x += 1

if ans < INF:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, Ma, Mb = inpl()
INF = 4001

DP = [[INF]*(411) for _ in range(411)]
DP[0][0] = 0

for _ in range(N):
    DP2 = [[INF]*(411) for _ in range(411)]
    a, b, c = inpl()
    for i in range(400):
        for j in range(400):
            DP2[i][j] = min(DP[i][j], DP2[i][j])
            DP2[i+a][j+b] = min(DP[i+a][j+b], DP[i][j] + c)
    DP = DP2

x = 1
ans = INF
while Ma*x <= 400 and Mb*x <= 400:
    ans = min(ans, DP[Ma*x][Mb*x])
    
    x += 1

if ans < INF:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
S = list(input().strip())
mod = 10**9+7
a = 0
ab = 0
ans = 0
q = 0
for c in S:
    if c == 'A':
        a += 3**q
    elif c == 'B':
        ab += a
    elif c == 'C':
        ans += ab
    elif c == '?':
        a, ab, ans, q = a*3+3**q, ab*3+a, ans*3+ab, q+1
    #a %= mod
    #ab %= mod
    #ans %= mod
    #q %= mod
    #print(c, a, ab, ans, q)
print(ans%mod)


### FIXED CODE ###

import sys
input = sys.stdin.readline
S = input().strip()
mod = 10**9+7
a = 0
ab = 0
ans = 0
q = 1
for c in S:
    if c == 'A':
        a += q
    elif c == 'B':
        ab += a
    elif c == 'C':
        ans += ab
    elif c == '?':
        a, ab, ans, q = a*3+q, ab*3+a, ans*3+ab, q*3
    a %= mod
    ab %= mod
    ans %= mod
    q %= mod
print(ans % mod)
### BUGGY CODE ###

n=int(input())
A=[int(input()) for i in range(n)]
for i in range(n):
  tmp=A[i]
  A[i]=0
  print(max(A))
  A[i]=tmp

### FIXED CODE ###

n=int(input())
A=[int(input()) for i in range(n)]
ma=max(A)
flag=False
if A.count(ma)>=2:
  flag=True
for i in range(n):
  if A[i] != ma:
    print(ma)
  else:
    if flag:
      print(ma)
    else:
      A[i]=0
      print(max(A))
### BUGGY CODE ###

N = int(input())
e = list(map(int,input().split()))
mod = 1000000007
kai = [0]*(N+3)
#被り探し
for i in range(N):
  d = e[i]
  e[i] = e[i]+ 9999999
  try:
    f = e.index(d)
    break
  except:
    pass
e = []
g = i +0
for i in range(N+3):
  if i ==0:
    kai[i] = 1
  else:
    kai[i] = (kai[i-1]*(i))%mod
def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=kai[n] %p
  b=kai[k] %p
  c=kai[n-k] %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
for j in range(N+1):
  print(comb(N+1,j+1,mod)-comb(g+N-f,j,mod))

### FIXED CODE ###

N = int(input())
e = list(map(int,input().split()))
mod = 1000000007
kai = [0]*(N+3)
from collections import Counter
c = Counter(e).most_common(1)[0][0]
g = e.index(c)
e.remove(c)
f = e.index(c) +1
e = []
for i in range(N+3):
  if i ==0:
    kai[i] = 1
  else:
    kai[i] = (kai[i-1]*(i))%mod
def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=kai[n] 
  b=kai[k] 
  c=kai[n-k] 
  b = pow(b,mod-2,mod)
  c = pow(c,mod-2,mod)
  return (a*b*c)%mod
h = [1]*((N+6)//2)
for j in range((N+4)//2):
  h[j+1] = comb(N+1,j+1,mod)
for j in range(N+1):
  if N-j>N/2:
    print((h[j+1]-comb(g+N-f,j,mod)+mod)%mod)
  else:
    print((h[N-j]-comb(g+N-f,j,mod)+mod)%mod)
### BUGGY CODE ###

N, M, P = map(int, input().split())

edge_array = []

for _ in range(M):
    A, B, C = map(int, input().split())
    edge_array.append([A-1, B-1, C-P])
# print(edge_dic)

INF = 10 ** 10

ans_array = [-INF] * N

ans_array[0] = 0
last_ans_change = -1

for i in range(N*2):
    change_flag = 0
    for edge in edge_array:
        a, b, c = edge
        if ans_array[b] < ans_array[a] + c:
            ans_array[b] = ans_array[a] + c
            change_flag = 1
            if b == N - 1:
                last_ans_change = i
    if change_flag == 0:
        break

if last_ans_change >= N:
    ans = -1
else:
    ans = max(0, ans_array[N-1])

print(ans)


### FIXED CODE ###

N,M,P = map(int,input().split())

edge_dic = {}

for _ in range(M):
    A,B,C = map(int,input().split())
    if not A - 1 in edge_dic:
        edge_dic[A-1] = [[B-1,C-P]]
    else:
        edge_dic[A-1].append([B-1,C-P])

# print(edge_dic)

INF = 10 ** 10

ans_array = [-INF] * N
can_visit = [0] * N
ans_array[0] = 0
can_visit[0] = 1 
last_ans_change = -1

for i in range(N*2):
    change_flag = 0
    for key, value in edge_dic.items():
        if can_visit[key] == 0:
            continue
        for v in value:
            goal, cost = v
            if ans_array[goal] < ans_array[key] + cost:
                ans_array[goal] = ans_array[key] + cost
                if i >= N:
                    ans_array[goal] = INF
                can_visit[goal] = 1
                change_flag = 1
                if goal == N - 1:
                    last_ans_change = i
                    if i >= N:
                        print(-1)
                        exit()
    if change_flag == 0:
        break


ans = max(0,ans_array[N-1])

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

# ABC 153 C

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

for _ in range(k):
    if len(H) != 0:
        H.remove(max(H))

print(sum(H))

### FIXED CODE ###

# ABC 153 C

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

H.sort()

for _ in range(k):
    if len(H) != 0:
        H.pop()
    else:
        break

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

# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
input_2 = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]


for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))



list_3 = []
list_4 = []

for w in range(int(Q)):
    word = input_2[(l[w]-1):(r[w])]
    word1 = ''.join(word)
    

    print(word.count('AC'))
    

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 10:49:27 2019

@author: adachi-lab
"""


input_1 = input()
S = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))
    
s_1 = []
x = 0
for w in range(len(S)-1):
    if S[w] == 'A' and S[w+1] == 'C':
        x += 1
        s_1.append(x)
    else:
        s_1.append(x)
        
s_1.insert(0,0)
w = []

for j in range(len(l)):
    p = s_1[r[j]-1]-s_1[l[j]-1]
    w.append(p)
    
for t in range(len(w)):
    print(w[t])
### BUGGY CODE ###

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

for _ in range(n):
  s = input()
  d[s] = d.get(s, 0) + 1 

max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]

for i in sorted(max_k_list):
  print(i)

### FIXED CODE ###

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

for _ in range(n):
  s = input()
  d[s] = d.get(s, 0) + 1 

n = max(d.values())
max_k_list = [kv[0] for kv in d.items() if kv[1] == n]
max_k_list.sort()

for i in max_k_list:
  print(i)
### BUGGY CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline

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

cnt = 1
for i in range(n):
    cnt = a[i] * cnt // gcd(a[i],cnt)


b = [cnt // a[i] for i in range(n)]
print(sum(b)%(10**9+7))


### FIXED CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline

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

cnt = 1
for i in range(n):
    cnt = a[i] * cnt // gcd(a[i],cnt)


b = [cnt // a[i] for i in range(n)]
print(sum(b)%(10**9+7))