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

from itertools import accumulate


def main():
    cells, can_jump = [int(x) for x in input().split()]
    jumps_from = [int(x) - 1 for x in input().split()]
    score_on = [int(x) for x in input().split()]

    ans = - 10**10
    for start in range(cells):
        route = []
        position = start
        while True:
            route.append(score_on[position])
            position = jumps_from[position]
            if position == start:  # Looped
                break

        length = len(route)
        total = sum(route)
        for jumping, accum_candidate in enumerate(accumulate(route)):
            jumping += 1
            if jumping > can_jump:
                break
            if total > 0:
                accum_candidate += total * ((can_jump - jumping) // length)
            ans = max(ans, accum_candidate)
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)


### FIXED CODE ###

from itertools import accumulate


def main():
    cells, moves = [int(x) for x in input().split()]
    jumps_from = [int(x) - 1 for x in input().split()]
    score_on = [int(x) for x in input().split()]

    ans = - 10**10
    for start in range(cells):
        route = []
        route_append = route.append
        position = start
        while True:
            route_append(score_on[position])
            position = jumps_from[position]
            if position == start:  # Looped
                break

        length = len(route)
        total = sum(route)
        accum_tmp = 0
        for i, score in enumerate(route):
            accum_tmp += score
            if i + 1 > moves:
                break
            accum = accum_tmp
            if total > 0:
                accum += total * ((moves - (i + 1)) // length)
            ans = max(ans, accum)

        # if total > 0:
        #     q, mod = divmod(moves, length)
        #     if mod == 0:
        #         candidate = total * q
        #     else:
        #         candidate = max(list(accumulate(route))[:mod]) + total * q
        # else:
        #     candidate = max(list(accumulate(route))[:min(moves, length)])
        # ans = max(ans, candidate)
    return ans


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

n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
data=[]
cnt=0
for i in range(n):
  if a.count(a[i])>=4:
    data.append(a[i])
    cnt+=1
    if cnt==2:
      break
    data.append(a[i])
    break
  elif 2<=a.count(a[i])<4:
    if a[i] not in data:
      data.append(a[i])
      cnt+=1
    if cnt==2:
      break
if len(data)==0 or len(data)==1:
  print(0)
else:
  print(data[0]*data[1])

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
A=Counter(a)
s=set(a)
S=sorted(list(s))
S.reverse()
h=0
w=0
for i in S:
  res=A[i]
  if res>=4:
    if h==0:
      h=i
    if w==0:
      w=i
  elif 2<=res<4:
    if w==0:
      w=i
    elif w!=0 and h==0:
      h=i
print(h*w)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(1, n):
    arr[i + 1] = arr[i] + a[i]
setarr = set(arr)
countarr = Counter(arr)
ans = 0
for i in range(n):
    s = arr[i]
    if s in setarr:
        ans += arr[i+1:].count(s)
print(ans)

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(2, n + 1):
    arr[i] = arr[i - 1] + a[i - 1]
arr2= Counter(arr)
arr3 = list(set(arr))
ans = 0
for i in range(len(arr3)):
    ans += arr2[arr3[i]] * (arr2[arr3[i]] - 1) // 2
print(ans)
### BUGGY CODE ###

N,Ma,Mb=map(int,input().split())
a,b,c=map(list,zip(*[list(map(int,input().split())) for i in range(N)]))
ma,mb=sum(a),sum(b)
MAX=5000
dp=[[[MAX]*(mb+1) for i in range(ma+1)] for j in range(N+1)]
dp[0][0][0]=0
for i in range(N):
    for j in range(ma):
        for k in range(mb):
            dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k])
            if j+a[i]<=ma and k+b[i]<=mb:
                dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i])
ans=MAX
x=1
while x*Ma<=ma and x*Mb<=mb:
    ans=min(ans,dp[N][x*Ma][x*Mb])
    x+=1
print(ans if ans<MAX else -1)

### FIXED CODE ###

N,Ma,Mb=map(int,input().split())
a,b,c=map(list,zip(*[list(map(int,input().split())) for i in range(N)]))
ma,mb=sum(a),sum(b)
MAX=5000
dp=[[[MAX]*(mb+1) for i in range(ma+1)] for j in range(N+1)]
dp[0][0][0]=0
for i in range(N):
    for j in range(ma):
        for k in range(mb):
            dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k])
            if j+a[i]<=ma and k+b[i]<=mb:
                dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i])
ans=MAX
x=1
while x*Ma<=ma and x*Mb<=mb:
    ans=min(ans,dp[N][x*Ma][x*Mb])
    x+=1
print(ans if ans<MAX else -1)
### BUGGY CODE ###

import numpy as np

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

As = np.sort(list(map(int,input().split())), kind="quicksort")

Bs = []
Cs = []
for i in range(M):
	inputs = list(map(int,input().split()))
	Bs.append(inputs[0])
	Cs.append(inputs[1])

for j in range(1, M + 1):
	for n in range(Bs[j - 1]):
		if As[n] < Cs[j - 1]:
			As[n] = Cs[j - 1]
	As = np.sort(As, kind="quicksort")

print(sum(As))


### FIXED CODE ###

import numpy as np

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

As = sorted(list(map(int,input().split())))
BCs = []

for i in range(M):
	inputs = list(map(int,input().split()))
	BCs.append(inputs)
BCs = sorted(BCs, reverse = True, key=lambda x: x[1])

index = 0
for bc in BCs:
	b = bc[0]
	c = bc[1]

	for n in range(b):
		try:
			if As[index] < c:
				As[index] = c
				index += 1
			else:
				break
		except:
			break
print(sum(As))
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n):
    if min(l[:i+1]) == l[i]:
        count += 1
print(count)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
m = l[0]
count = 1
for i in range(1,n):
    if m > l[i]:
        count += 1
        m = l[i]
print(count)
### BUGGY CODE ###

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

A = [A.index(i)+1 for i in range(1,N+1)]
print(*A)

### FIXED CODE ###

# C - Go to School TLE
N = int(input())
A = list(map(int, input().split()))

attend = [i for i in range(1,N+1)]
for j in range(1,N+1):
    attend[A[j-1] - 1] = j
print(*attend)
### BUGGY CODE ###

s=input()
k=2019
numMultiples = 0
seenRemainders = []
for i in range(len(s)):
  l=[]
  seenRemainders.append(l)
for i in range(len(s)):
    remainder = 0
    prefixesFound = 0
    for j in range(i,len(s)):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder not in seenRemainders[j]:  
            seenRemainders[j].append(remainder)
        else:
            break
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) // 2
print(numMultiples)

### FIXED CODE ###

mod=2019
s=input()

d={}
temp=1
cnt=0
we=0
d[0]=1
for i in range(len(s)):
  we=(we+int(s[-1-i])*temp)%mod
  temp=temp*10%mod
  
  if we not in d:
    d[we]=1
  else:
    d[we]+=1

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

n = int(input())
S = input()
ans = 0
cnt = 0
for d in range(n):
    for i in range(n-d):
        if S[i] == S[d+i]:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, min(cnt, d))
print(ans)


### FIXED CODE ###

n = int(input())
S = input()
ans = 0
for d in range(n):
    cnt = 0
    for i in range(n-d):
        if S[i] == S[d+i]:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, min(cnt, d))
print(ans)
### BUGGY CODE ###

def gcd(a,b):
  r = a%b
  while r > 0:
    a=b
    b=r
    r=a%b
  return b

n = int(input())
A = list(map(int,input().split()))
num = 1
ans = 0
for i in A:
  num = i // gcd(i,num) * num

for i in A:
  ans += num//i
  ans %= 1000000007
  
print(int(ans))

### FIXED CODE ###

from fractions import gcd


n = int(input())
A = list(map(int,input().split()))
num = 1
ans = 0
for i in A:
  num = i // gcd(i,num) * num

for i in A:
  ans += num//i
  
print(int(ans%1000000007))
### BUGGY CODE ###

L, R = map(int, input().split(' '))

N = 2019

if R - L == 1:
    print((R * L) % N)
    exit(0)

q = L // N
L_min = L % N
R_min = R - N * q

ans = 2019

for i in range(L_min, R_min):
    for j in range(i + 1, R_min + 1):
        mod = (i * j) % N
        if ans > mod:
            ans = mod

print(ans)

### FIXED CODE ###

L, R = map(int, input().split(' '))

N = 2019


ans = 2019

for i in range(L, R):
    for j in range(i + 1, R + 1):
        mod = (i * j) % N
        if ans > mod:
            ans = mod
        if ans == 0:
            print(ans)
            exit(0)

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

import math
denom = int(1e9+7)

def combi(n,r):
    return (int(math.factorial(n)) // int(math.factorial(r)) // int(math.factorial(n - r))) % denom


def combi2(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(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

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)

max_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom)) % denom
min_tot = 0
for i in range(N-K+1):
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom)) % denom
    
print((max_tot - min_tot)%denom)

### FIXED CODE ###

import math
denom = int(1e9+7)

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


def combi2(n,k,p,f,pow_fun):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=fact_mod[n]
  b=fact_mod[k]
  c=fact_mod[n-k]
  return (a*pow_fun[b]*pow_fun[c])%p


N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)

fact_mod = [1]
current = 1
for i in range(1,N+1):
    current = (current * i) % denom
    fact_mod.append(current)

pow_fun = {}
for i in fact_mod:
    pow_fun[i]=power_func(i,denom-2,denom)

max_tot = 0
min_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    
print((max_tot - min_tot)%denom)
### BUGGY CODE ###

N = int(input())
S = input()
cnt = []
for i in range(N):
  left = S[0:i]
  right = S[i+1:int(N)]
  cnt.append(left.count('W') + right.count('E'))
print(min(cnt))

### FIXED CODE ###

N = int(input())
S = input()
E = S.count('E')
W = N - E
result = N
l = 0
r = E
for i in S:
  if i == 'E':
    r-=1
    result = min(result, l+r)
  elif i == 'W':
    result = min(result, l+r)
    l+=1

print(result)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
R = [0] * (N + 1)
for i in range(N):
  R[i + 1] += R[i] + A[i]
#print(R)  

ans = 10 ** 15
for i in range(3, N):#R[:i]とR[i:]に切る
  #left = R[:i]
  #right = R[i]
  left, right = 10 ** 15, 10 ** 15
  a, b, c, d = 0, 0, 0, 0
  for j in range(2, i):#左側
    one = R[j - 1]
    two = R[i - 1] - one
    if left > abs(two - one):
      left = abs(two - one)
      a, b = one, two
    
  for j in range(i + 1, N + 1):#右側  
    three = R[j - 1] - R[i - 1]
    four = R[N] - R[j - 1]
    if right > abs(three - four):
      right = abs(three - four)
      c, d = three, four
    
  T = [a, b, c, d]  
  ans2 = max(T) - min(T)
  ans = min(ans, ans2)
  #print(a, b, c, d, ans, ans2)
print(ans)
    
  
  

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
R = [0] * (N + 1)
for i in range(N):
  R[i + 1] += R[i] + A[i]
#print(R)  

ans = 10 ** 15
l, r = 2, 4
for i in range(3, N):#R[:i]とR[i:]に切る
  #R[:l], R[l:i], R[i:r], R[r:]
  #R[l - 1] と R[i - 1] - R[l - 1] の差を考える
  
  while abs(R[i - 1] - 2 * R[l]) <= abs(R[i - 1] - 2 * R[l - 1]):
    l += 1
    
  #R[r - 1] - R [i - 1] と R[N] - R[r - 1] の差を考える  
  while abs(R[N] - 2 * R[r] + R[i - 1]) <= abs(R[N] - 2 * R[r - 1] + R[i - 1]):
    r += 1  
  
  now_max = max(max(R[l - 1], R[i - 1] - R[l - 1]), max(R[r - 1] - R[i - 1], R[N] - R[r - 1]))
  now_min = min(min(R[l - 1], R[i - 1] - R[l - 1]), min(R[r - 1] - R[i - 1], R[N] - R[r - 1]))
  ans = min(ans, now_max - now_min)
  #print(R[l - 1], R[i - 1] - R[l - 1],R[r - 1] - R[i - 1], R[N] - R[r - 1], ans)
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
ans_list = []
for _ in range(N):
    A=int(input())
    if A in ans_list:
        ans_list.remove(A)
    else:
        ans_list.append(A)

print(len(ans_list))


### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
An = []
for _ in range(N):
    An.append(int(input()))

ans_dict = {}
for A in An:
    if A in ans_dict:
        ans_dict[A] = abs(ans_dict[A] - 1)
    else:
        ans_dict[A] = 1

sum = 0
for i in ans_dict.values():
    sum += i

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

A, B = tuple(map(int, input().split()))
res = A
for i in range(A+1, B+1):
    res = res ^ i
print(res)

### FIXED CODE ###

def xor(n):
    ans = None
    if (n + 1) % 2 == 0:
        if ((n + 1) // 2) % 2 == 0:
            ans = 0
        else:
            ans = 1
    else:
        if ((n +  1) // 2) % 2 == 0:
            ans = 0 ^ n
        else:
            ans = 1 ^ n
    return ans

A, B = tuple(map(int, input().split()))
print(xor(A-1) ^ xor(B))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
n = int(input())
G = [[] for _ in range(n)]
mod = 10**9 + 7

for _ in range(n-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

stack = [0]
depth = [-1]*n
depth[0] = 0
while stack:
    v = stack.pop()
    d = depth[v]
    for nv in G[v]:
        if depth[nv] >= 0:continue
        depth[nv] = depth[v] + 1
        stack.append(nv)

d_to_i = [[] for _ in range(n)]

for i in range(n):
    d_to_i[depth[i]].append(i)

data = [[] for _ in range(n)]

for d in range(n-1,-1,-1):
    for v in d_to_i[d]:
        for nv in G[v]:
            if depth[nv] < depth[v]:continue
            if data[nv]:
                data[v].append(n-data[nv][-1])
        if data[v]:
            data[v].append(n-1-sum(data[v]))
        else:
            data[v].append(n-1)

ans = 0
for i in range(n):
    now = pow(2,n-1,mod)-1
    for x in data[i]:
        now -= pow(2,x,mod)-1
        now %= mod
    ans += now

#print(ans)

x = pow(2,n,mod)
x = pow(x,mod-2,mod)
print(ans*x%mod)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n = int(input())
G = [[] for _ in range(n)]
mod = 10**9 + 7

for _ in range(n-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

stack = [0]
depth = [-1]*n
depth[0] = 0
while stack:
    v = stack.pop()
    d = depth[v]
    for nv in G[v]:
        if depth[nv] >= 0:continue
        depth[nv] = depth[v] + 1
        stack.append(nv)

d_to_i = [[] for _ in range(n)]

for i in range(n):
    d_to_i[depth[i]].append(i)

data = [[] for _ in range(n)]

for d in range(n-1,-1,-1):
    for v in d_to_i[d]:
        for nv in G[v]:
            if depth[nv] < depth[v]:continue
            if data[nv]:
                data[v].append(n-data[nv][-1])
        if data[v]:
            data[v].append(n-1-sum(data[v]))
        else:
            data[v].append(n-1)

ans = 0
two = [1]
for i in range(n):
    two.append(two[-1]*2%mod)
for i in range(n):
    now = two[n-1]-1
    for x in data[i]:
        now -= two[x]-1
        now %= mod
    ans += now

#print(ans)

x = two[n]
x = pow(x,mod-2,mod)
print(ans*x%mod)
### BUGGY CODE ###

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

YES = "Yes"  # type: str
NO = "No"  # type: str


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

    A = deque(A)
    a = deque()

    p = 1
    for i in range(K):
        t=A.popleft()
        p*=t
        a.append(t)
    
    for i in range(K, N):
        pre = p
        t = A.popleft()
        p = p // a.popleft() * t
        if p > pre: print(YES)
        else: print(NO)
        pre = p
        a.append(t)

    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
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

YES = "Yes"  # type: str
NO = "No"  # type: str


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

    A = deque(A)
    a = deque()

    p = 1
    for i in range(K):
        t=A.popleft()
        a.append(t)
    
    for i in range(K, N):
        t = A.popleft()
        c = a.popleft()
        if t > c: print(YES)
        else: print(NO)
        a.append(t)

    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
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

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

import sys

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())) + [-1])
flags = [False for i in range(n)]
nums = [0 for i in range(n)]
day = 0
flag = True
while False in flags:
    if flag == False:
        break
    match = set()
    for i in range(n):
        if nums[i] == n - 1:
            continue
        num = a[i][nums[i]] - 1
        if nums[num] == n - 1:
            flag = False
            break
        if a[num][nums[num]] - 1 == i:
            if i not in match and num not in match:
                match.add(i)
                match.add(num)
                nums[i] += 1
                nums[num] += 1
                if nums[i] == n - 1:
                    flags[i] = True
                if nums[num] == n - 1:
                    flags[num] = True
    if not match:
        flag = False
        break
    day += 1
if flag == True:
    print(day)
else:
    print(-1)

### FIXED CODE ###

import sys, collections
input = sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
nums = [0 for i in range(n)]
day = 0
match = 0
flag = True
queue = collections.deque([])
temp = set()
for i in range(1, n + 1):
    i2 = a[i - 1][0]
    if a[i2 - 1][0] == i:
        if i not in temp:
            queue.append([i, i2])
            temp.add(i)
            temp.add(i2)
if not queue:
    flag = False
while queue:
    temp = []
    while queue:
        test = queue.popleft()
        match += 1
        num1, num2 = test[0], test[1]
        nums[num1 - 1] += 1
        nums[num2 - 1] += 1
        temp.append(num1)
        temp.append(num2)
    flag2 = False
    temp2 = set()
    for i in temp:
        if nums[i - 1] <= n - 2:
            new_num = a[i - 1][nums[i - 1]]
            if nums[new_num - 1] <= n - 2 and a[new_num - 1][nums[new_num - 1]] == i:
                if i not in temp2:
                    queue.append([i, new_num])
                    flag2 = True
                    temp2.add(i)
                    temp2.add(new_num)
    if flag2 == False and match < n * (n - 1) // 2:
        flag = False
        break
    day += 1

if flag == True:
    print(day)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n):
    if min(p[:i+1]) == p[i]:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
min_p = n+1
ans = 0
for i in range(n):
    if p[i] < min_p:
        ans += 1
        min_p = p[i]
print(ans)
### BUGGY CODE ###

import numpy as np
from numba import njit

@njit
def main(N, s, dpt):
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if s[j-1] == s[i-1]:
                if j - dpt[i-1][j-1] > i:
                    dpt[i][j] = dpt[i-1][j-1] + 1

    result = 0
    for i in range(N + 1):
        result = max(result, max(dpt[i]))

    return result

if __name__ == '__main__':
    N = int(input())
    s = np.array([c for c in input()], dtype='str')

    dpt = np.array([[0] * (N + 1) for i in range(N + 1)])

    print(main(N, s, dpt))


### FIXED CODE ###

import numpy as np
from numba import njit
 
@njit(cache=True)
def main(N, s):
    dpt = np.zeros((N+1, N+1), dtype=np.int16)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if s[j-1] == s[i-1]:
                if j - dpt[i-1][j-1] > i:
                    dpt[i][j] = dpt[i-1][j-1] + 1
 
    return np.amax(dpt)
 
if __name__ == '__main__':
    N = int(input())
    s = np.array([ord(c) for c in input()]) 
 
    print(main(N, s))
### BUGGY CODE ###

# coding: utf-8
import sys
from fractions import gcd
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7

N = ir()
A = lr()
lcm = 1
for a in A:
    lcm *= a // gcd(lcm, a)

A = np.array(A)
answer = (lcm // A % MOD).sum() % MOD
print(answer % MOD)
# np.int64とint型の違いに注意

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
#リストの最小公倍数
def lcm(a):    
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

N = ir()
A = lr()
A.sort()
if N == 1:
    print(1)
    exit()
MOD = 10 ** 9 + 7
l = []
first = A[0]
l = [x//gcd(x, first) for x in A[1:]]
x = lcm(l) #B[0]
answer = x%MOD

for i in range(1, N):
    answer += first * x // A[i]

print(answer%MOD)