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

N,M=map(int,input().split())
H=list(map(int,input().split()))
Loser=[]
for i in range(M):
  A,B=map(int,input().split())
  Low = A if H[A-1]< H[B-1] else B
  if H[A-1] != H[B-1] and not(Low in Loser):
    Loser.append(Low)
  elif H[A-1] == H[B-1]:
    if not(A in Loser):
      Loser.append(A)
    if not(B in Loser):
      Loser.append(B)  
print(N-len(Loser))      

### FIXED CODE ###

N,M=map(int,input().split())
H=list(map(int,input().split()))
Loser=[]
for i in range(M):
  A,B=map(int,input().split())
  Low = A if H[A-1]< H[B-1] else B
  if H[A-1] != H[B-1] and not(Low in Loser):
    Loser.append(Low)
  elif H[A-1] == H[B-1]:
    if not(A in Loser):
      Loser.append(A)
    if not(B in Loser):
      Loser.append(B)  
print(N-len(Loser))
### BUGGY CODE ###

import numpy as np
H,W=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]

#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[[] for _ in range(W)] for _ in range(H)]
dp[0][0].append(0)

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = A[I][J] - B[I][J]
    for point in dp[I][J]:
      if I!=H-1:
        dp[I+1][J].append(point+sa)
        dp[I+1][J].append(point-sa)
      if J!=W-1:
        dp[I][J+1].append(point+sa)
        dp[I][J+1].append(point-sa)
    I-=1
    J+=1

ans=dp[H-1][W-1]
sa = A[H-1][W-1] - B[H-1][W-1]
res=float("inf")
for p in ans:
  res=min(res,abs(p+sa),abs(p-sa))
print(res)

### FIXED CODE ###

H,W=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]

#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(0)

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for point in dp[I][J]:
      if I!=H-1:
        dp[I+1][J].add(point+sa)
        dp[I+1][J].add(abs(point-sa))
      if J!=W-1:
        dp[I][J+1].add(point+sa)
        dp[I][J+1].add(abs(point-sa))
    I-=1
    J+=1

ans=dp[H-1][W-1]
sa = abs(A[H-1][W-1] - B[H-1][W-1])
res=float("inf")
for p in ans:
  res=min(res,abs(p+sa),abs(p-sa))
print(res)
### BUGGY CODE ###

def isOdd(num):
	if num % 2 == 0:
		return False
	else:
		return True

A, B, C = map(int, raw_input().split())
ans = 0
while not isOdd(A) and not isOdd(B) and not isOdd(C):
	ans += 1
	A, B, C = B/2 + C/2, A/2 + C/2, A/2 + B/2
print ans


### FIXED CODE ###

A, B, C = map(int, raw_input().split())
[A, B, C] = sorted([A, B, C])
ans = 0
while A%2==0 and B%2==0 and C%2==0:
	ans += 1
	new1, new2, new3 = B/2 + C/2, A/2 + C/2, A/2 + B/2
	if new1 == new3:
		ans = -1
		break
	else:
		A, B, C = new1, new2, new3
print ans
### BUGGY CODE ###

def main():
    INF = float('inf')
    H,N = map(int,input().split())
    A,B = [0]*N,[0]*N
    for i in range(N):
        A[i],B[i] = map(int,input().split())
    dp = [INF]*(H+max(A)+1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == INF:
            continue
        else:
            for j in range(N):
                if dp[i]+B[j] < dp[i+A[j]]:
                    dp[i+A[j]] = dp[i]+B[j]
    print(min(dp[H:]))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H,N = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(N)]
    maxA = max(A for A,B in AB)
    dp = [0]*(H+maxA)
    for i in range(0,H+maxA):
        if i <= 0:
            dp[i] = 0
        else:
            dp[i] = min(dp[i-A]+B for A,B in AB)
    print(min(dp[H:]))


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

# import numpy as np

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

p = 1
for i in a:
    p *= i



if p > 10**18:
    print(-1)
else:
    print(p)

### FIXED CODE ###

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

if 0 in a:
    print(0)
    exit()

p = 1
for i in a:
    p *= i
    # print(p)
    if p > 10**18:
        print(-1)
        exit()
print(p)
### BUGGY CODE ###

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

if P == 2 or P == 5:
    res = 0

    for i in range(N):
        if int(S[i]) % P == 0:
            res += i + 1
    
    print(res)

else:
    res = 0
    count = [0] * P

    for i in range(N-1, -1, -1):
        n = int(S[i:N])
        r = n % P
        if r == 0: res += 1
        res += count[r]
        count[r] += 1
    
    print(res)


### FIXED CODE ###

def solve():
    N, P = map(int, input().split())
    S = input()

    if P == 2 or P == 5:
        res = 0

        for i in range(N):
            if int(S[i]) % P == 0:
                res += i + 1
        
        print(res)

    else:
        res = 0
        count = [0] * P
        r = 0

        for i in range(N-1, -1, -1):
            r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P
            if r == 0: res += 1
            res += count[r]
            count[r] += 1
        
        print(res)

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

n=int(input())
l1=[0]*61
l=list(map(int,input().split()))
for j in range(n):
  s=list(str(bin(l[j])))
  for i in range(61):
    if i==len(s)-2:
      break
    if s[-i-1]=='1':
      l1[i]+=1
c=0
for i in range(61):
  c+=pow(2,i,10**9+7)*(n-l1[i])*l1[i]%(10**9+7)
print(c%(10**9+7))

### FIXED CODE ###

n=int(input())
l1=[0]*61
l=list(map(int,input().split()))
for j in range(n):
  s=list(str(bin(l[j])))
  for i in range(61):
    if i==len(s)-2:
      break
    if s[-i-1]=='1':
      l1[i]+=1
c=0
for i in range(61):
  c+=pow(2,i,10**9+7)*(n-l1[i])*l1[i]%(10**9+7)
print(c%(10**9+7))
### BUGGY CODE ###

def solve():
    N, M = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    A.sort()
    BC = []
    for i in range(M):
        Bi, Ci = [int(_) for _ in raw_input().split()]
        BC.append([Bi, Ci])
    BC.sort(key = lambda x: x[1], reverse = True)
    for i in range(M):
        Bi = BC[i][0]
        Ci = BC[i][1]
        low_ind = 0
        up_ind = N - 1
        found = None
        if A[low_ind] > Ci:
            continue
        elif A[up_ind] < Ci:
            A = A[Bi:]
            A.extend([Ci] * Bi)
            continue
        while (up_ind - low_ind) > 1:
            mid = (up_ind + low_ind) / 2
            if A[mid] < Ci:
                low_ind = mid
            elif A[mid] > Ci:
                up_ind = mid
            elif A[mid] == Ci:
                found = mid
                break
        if found is not None:
            cnt = found
        else:
            cnt = up_ind
        repl = min(cnt,Bi)
        for i in range(repl):
            A.insert(i + cnt, Ci)
        A = A[repl:]
    print sum(A)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N, M = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    A.sort(reverse = True)
    BC = []
    for i in range(M):
        Bi, Ci = [int(_) for _ in raw_input().split()]
        BC.append([Bi, Ci])
    BC.sort(key = lambda x: x[1], reverse = True)
    ind_BC = 0
    ind_A = 0
    merged = []
    while ind_A < N and ind_BC < M:
        Bi = BC[ind_BC][0]
        Ci = BC[ind_BC][1]
        if A[ind_A] > Ci:
            merged.append(A[ind_A])
            ind_A += 1
        else:
            merged.extend([Ci] * Bi)
            ind_BC += 1
        if len(merged) >= N:
            break
    if len(merged) < N:
        if ind_A < N:
            merged.extend(A[ind_A:])
        elif ind_BC < M:
            for i in range(ind_BC, M):
                Bi = BC[ind_BC][0]
                Ci = BC[ind_BC][1]
                merged.extend([Bi] * Ci)
                if len(merged) >= N:
                    break
    merged = merged[:N]
    print sum(merged)

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

n = int(input())

L = [0] * (n + 1)
for x in range(1, n + 1):
    for y in range(1, n - x):
        for z in range(1, n - x - y):
            tmp = x * x + y * y + z * z + x * y + y * z + z * x
            if tmp <= n:
                L[tmp] += 1
            # print(x, y , z)

for l in L[1:]:
    print(l)

### FIXED CODE ###

import math

n = int(input())
max = int(math.sqrt(n) + 1)
L = [0] * (n + 1)
for x in range(1, max):
    for y in range(1, max):
        for z in range(1, max):
            tmp = x * x + y * y + z * z + x * y + y * z + z * x
            if tmp > n:
                continue
            L[tmp] += 1

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

n = int(input())
import math
import random
s = [1 for i in range(55555+1)]
s[0], s[1] = 0, 0
for i in range(2, int(math.sqrt(55555))+1):
    if s[i] != 0:
        for j in range(i*2, 55555, i):
            s[j] = 0
prime = []
for i in range(55555+1):
    if s[i] == 1:
        prime.append(i)

def is_prime(q):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False
    return pow(2, q - 1, q) == 1








while True:
    a = random.sample(prime, n)
    count = 0
    while True:
        b = random.sample(a, 5)
        if is_prime(sum(b)):
            break
        else:
            count += 1
        if count > 1000:
            ans = ''
            for i in a:
                ans += str(i) + ' '
            print(ans[:-1])
            # print(sum(a))
            # print(is_prime(sum(a)))
            quit()


### FIXED CODE ###

n = int(input())
import math
import random
s = [1 for i in range(55555+1)]
s[0], s[1] = 0, 0
for i in range(2, int(math.sqrt(55555))+1):
    if s[i] != 0:
        for j in range(i*2, 55555, i):
            s[j] = 0
prime = []
for i in range(55555+1):
    if s[i] == 1:
        if str(i)[-1] == '1':
            prime.append(i)

def is_prime(q):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False
    return pow(2, q - 1, q) == 1




ans = ''
for i in range(n):
    ans += str(prime[i]) + ' '
print(ans[:-1])
# print(is_prime(sum(a)))
quit()
### BUGGY CODE ###

S = input()
Q = int(input())
Query = []
kaisu = 0
for i in range(Q):
    Query.append(input().split())

for i in Query:
    if int(i[0]) == 1:
        kaisu = kaisu + 1
    elif int(i[0]) == 2:
        if kaisu % 2 == 0:
            if int(i[1]) == 1:
                S = i[2] + S
            else:
                S = S + i[2]
        else:
            if int(i[1]) == 2:
                S = i[2] + S
            else:
                S = S + i[2]

if kaisu % 2 == 0:
    print(S)
else:
    print(''.join(list(reversed(S))))

### FIXED CODE ###

S = input()
Q = int(input())
Query = []
kaisu = 0
sento = ""
for i in range(Q):
    Query.append(input().split())

for i in Query:
    if int(i[0]) == 1:
        kaisu = kaisu + 1
    elif int(i[0]) == 2:
        if kaisu % 2 == 0:
            if int(i[1]) == 1:
                sento = sento + i[2]
            else:
                S = S + i[2]
        else:
            if int(i[1]) == 2:
                sento = sento + i[2]
            else:
                S = S + i[2]
S = ''.join(list(reversed(sento))) + S
if kaisu % 2 == 0:
    print(S)
else:
    print(''.join(list(reversed(S))))
### BUGGY CODE ###

import itertools
n,m,r = map(int, input().split())
towns = list(map(int, input().split()))
INF = float("inf")
cost = [[INF] * n for _ in range(n)]
#同じ場所にはコスト0で移動（というか移動しないので０）
for i in range(n):
    cost[i][i] = 0

for i in range(m):
    a,b,c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

# ワーシャルフロイド法
# スタート、中継地点、ゴールを全組み合わせで見ていくことで、ある地点からある地点への最短距離を求める
# 負の閉路があるとコストがいくらでも下げられるので使えない
for k in range(n): #中継地点
    for i in range(n): #スタート
        for j in range(n): #ゴール
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])


ans = INF

for node in itertools.permutations(range(r)): #町移動順の全組み合わせを作成
    tmp = 0
    for x, y in zip(node, node[1:]):
        s, g = towns[x], towns[y] 
        tmp += cost[s-1][g-1] # 町ｓからｇまでの最短距離を足していく
    ans = min(ans, tmp)

print(ans)

### FIXED CODE ###

import itertools
n,m,r = map(int, input().split())
towns = list(map(int, input().split()))
INF = float("inf")
cost = [[INF] * n for _ in range(n)]
#同じ場所にはコスト0で移動（というか移動しないので０）
for i in range(n):
    cost[i][i] = 0

for i in range(m):
    a,b,c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

# ワーシャルフロイド法
# スタート、中継地点、ゴールを全組み合わせで見ていくことで、ある地点からある地点への最短距離を求める
# 負の閉路があるとコストがいくらでも下げられるので使えない
for k in range(n): #中継地点
    for i in range(n): #スタート
        for j in range(n): #ゴール
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])


ans = INF

for node in itertools.permutations(range(r)): #町移動順の全組み合わせを作成
    tmp = 0
    for x, y in zip(node, node[1:]):
        s, g = towns[x], towns[y] 
        tmp += cost[s-1][g-1] # 町ｓからｇまでの最短距離を足していく
    ans = min(ans, tmp)

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

import math
from functools import reduce

def gcd(*num):
    return reduce(math.gcd, num)

N = int(input())

count = 0
for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            count = count + gcd(i, j, k)
print(count)

### FIXED CODE ###

n = int(input())

from math import gcd

y = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        x = gcd(i, j)
        for k in range(1, n + 1):
            y += gcd(x, k)

print(y)
### BUGGY CODE ###

num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
c = 0
for i in range(len(words)-1):
    for j in range(i+1, len(words)):
        if words[i] == words[j]:
            c += 1
print(c)

### FIXED CODE ###

from collections import Counter

num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
x = Counter(words)
res = 0
for c in x.values():
    res += (c**2 - c)//2
print(res)
### BUGGY CODE ###

import bisect
from collections import defaultdict, deque

n, m = map(int, input().split())
d = defaultdict(list)

queue = deque()
for i in range(m):
    p, y = map(int, input().split())
    queue.append((p, y))
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

while queue:
    p, y = queue.popleft()
    index = d[p].index(y)
    print('{:06d}{:06d}'.format(p, index + 1))

### FIXED CODE ###

from collections import defaultdict
import bisect

n, m = map(int, input().split())
d = defaultdict(list)

queue = []
for i in range(m):
    p, y = map(int, input().split())
    d[p].append((y, i))

arr = [0] * m
for k, v in d.items():
    for i, item in enumerate(sorted(v, key=lambda x: x[0])):
        arr[item[1]] = (k, i)

for k, v in arr:
    print('{:06d}{:06d}'.format(k, v + 1))
### BUGGY CODE ###

import sys

n, *inp = map(int, sys.stdin.buffer.read().split())
vvv = [0] + inp[0:n * 2:2]
www = [0] + inp[1:n * 2:2]

weight_limit = 10 ** 5
precalc_limit = min(1 << 1, n + 1)
precalc = [[0] * (weight_limit + 1)]

for u in range(1, precalc_limit):
    v = vvv[u]
    w = www[u]
    dp = precalc[u >> 1][:]
    for x in range(weight_limit, w - 1, -1):
        nv = dp[x - w] + v
        if dp[x] < nv:
            dp[x] = nv
    precalc.append(dp)

buf = []
mp = iter(inp[n * 2 + 1:])
for u, l in zip(mp, mp):
    if u < precalc_limit:
        buf.append(precalc[u][l])
        continue
    dp = {0: 0}
    while u >= precalc_limit:
        v = vvv[u]
        w = www[u]
        for cw, cv in list(dp.items()):
            nw = cw + w
            nv = cv + v
            if nw > l:
                continue
            if nw not in dp or dp[nw] < nv:
                dp[nw] = nv
        u >>= 1
    ans = max(v + precalc[u][l - w] for w, v in dp.items())
    buf.append(ans)

print('\n'.join(map(str, buf)))


### FIXED CODE ###

import sys

n, *inp = map(int, sys.stdin.buffer.read().split())
vvv = [0] + inp[0:n * 2:2]
www = [0] + inp[1:n * 2:2]

weight_limit = 10 ** 5
precalc_limit = min(1 << 10, n + 1)
precalc = [[0] * (weight_limit + 1)]

for u in range(1, precalc_limit):
    v = vvv[u]
    w = www[u]
    dp = precalc[u >> 1][:]
    for x in range(weight_limit, w - 1, -1):
        nv = dp[x - w] + v
        if dp[x] < nv:
            dp[x] = nv
    precalc.append(dp)

buf = []
mp = iter(inp[n * 2 + 1:])
for u, l in zip(mp, mp):
    if u < precalc_limit:
        buf.append(precalc[u][l])
        continue
    dp_w = [0]
    dp_v = [0]
    while u >= precalc_limit:
        v = vvv[u]
        w = www[u]
        for i in range(len(dp_w)):
            nw = dp_w[i] + w
            if nw > l:
                continue
            nv = dp_v[i] + v
            dp_w.append(nw)
            dp_v.append(nv)
        u >>= 1
    ans = 0
    for w, v in zip(dp_w, dp_v):
        nv = v + precalc[u][l - w]
        if ans < nv:
            ans = nv
    buf.append(ans)

print('\n'.join(map(str, buf)))
### BUGGY CODE ###

# coding: utf-8

"""
20191120
構成法
穴あき
"""


def main():
    N, W = map(int, input().split())
    ws = [None for _ in range(N)]
    vs = [None for _ in range(N)]
    for i in range(N):
        ws[i], vs[i] = map(int, input().split())

    # initialize
    dp = [[None for _ in range(W+1)] for _ in range(N)]
    dp[0][0] = 0
    existance = [set([]) for _ in range(N)]
    existance[0].add(0)
    if W >= ws[0]:
        dp[0][ws[0]] = vs[0]
        existance[0].add(ws[0])

    for n in range(N-1):
        for w in existance[n]:
            # not-use-update
            if dp[n+1][w] is None:
                dp[n+1][w] = dp[n][w]
            else:
                dp[n+1][w] = max(dp[n][w], dp[n+1][w])
            existance[n+1].add(w)

            # use-update
            if w + ws[n+1] <= W:
                if dp[n+1][w+ws[n+1]] is None:
                    dp[n+1][w+ws[n+1]] = dp[n][w] + vs[n+1]
                else:
                    dp[n+1][w+ws[n+1]] = max(dp[n][w] + vs[n+1], dp[n+1][w+ws[n+1]])
                existance[n+1].add(w+ws[n+1])
    # print(np.array(dp))

    ans = 0
    for w in range(1, W+1):
        if dp[-1][w] is not None and dp[-1][w] > ans:
            ans = dp[-1][w]

    return ans


if __name__ == "__main__":
    print(main())

### FIXED CODE ###

# coding: utf-8

# import numpy as np

"""
20191119
24分ギブアップ
質問

20191120
12分
"""


def main():
    N, W = map(int, input().split())
    ws = [None for _ in range(N)]
    vs = [None for _ in range(N)]
    for i in range(N):
        ws[i], vs[i] = map(int, input().split())

    dp = [[0 for _ in range(W+1)] for _ in range(N)]

    for n in range(N):
        for w in range(W+1):
            if w >= ws[n]:
                dp[n][w] = max(dp[n-1][w-ws[n]]+vs[n], dp[n-1][w])  # use or not use
            else:
                dp[n][w] = dp[n-1][w]  # not use

    return max(dp[-1])


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

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

from functools import lru_cache

def main(): 
    N = II()
    h = LI()

    @lru_cache()
    def min_cost(x):
        if x == 0: return 0
        elif x == 1: return abs(h[1] - h[0])
        else: return min(min_cost(x-1) + abs(h[x] - h[x-1]), min_cost(x-2) + abs(h[x] - h[x-2]))

    print(min_cost(N-1))

main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

from functools import lru_cache

def main(): 
    N = II()
    h = LI()

    @lru_cache()
    def min_cost(x):
        if x == 0: return 0
        elif x == 1: return abs(h[1] - h[0])
        else: return min(min_cost(x-1) + abs(h[x] - h[x-1]), min_cost(x-2) + abs(h[x] - h[x-2]))

    print(min_cost(N-1))

main()
### BUGGY CODE ###

from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = [0] * 10 ** 6
ans = 0

for i in range(N):
    tmp = 1
    a = A[i]
    g_tmp = {}
    while tmp <= A[i] ** 0.5:
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            if tmp not in g_tmp:
                g_tmp[tmp] = 1
            else:
                g_tmp[tmp] += 1
        tmp += 1
    if a > 1:
        if a not in g_tmp:
            g_tmp[a] = 1
        else:
            g_tmp[a] += 1

    for j in g_tmp:
        g[j] = max(g[j], g_tmp[j])

l = 1
ans = 0
for i in range(len(g)):
    l *= pow(i, g[i], mod)
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

print(ans)

### FIXED CODE ###

from sys import stdin
from collections import defaultdict

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = defaultdict(int)

for i in range(N):
    tmp = 1
    a = A[i]
    while tmp <= A[i] ** 0.5:
        cnt = 0
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            cnt += 1
        if cnt > 0:
            g[tmp] = max(g[tmp], cnt)
        tmp += 1
    if a > 1:
        if a not in g:
            g[a] = 1

l = 1
ans = 0
for i in g:
    l *= pow(i, g[i], mod)
    l %= mod
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

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

N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))
BC = [list(map(int, input().split())) for _ in range(M)]
D = [[],[]]

for i in range(len(BC)):
    D[1].append(BC[i][0])
    D[0].append(BC[i][1])

def matome(A):
    C = [[],[]]
    A.sort()
    for i in range(len(A)):
        if A[i] not in C[0]:
            C[0].append(A[i])
            C[1].append(1)
        else:
            C[1][C[0].index(A[i])] += 1
    return(C)

X = matome(X)

def futatu(A,B):
    for i in range(len(B[0])):
        if B[0][i] not in A[0]:
            A[0].append(B[0][i])
            A[1].append(B[1][i])
        else:
            A[1][A[0].index(B[0][i])] += B[1][i]
    return(A)

X = futatu(X,D)

def henkan(A):
    C = []
    for i in range(len(A[0])):
        C.append([A[0][i],A[1][i]])
    return(C)

X = sorted(henkan(X),reverse=True)

maisuu = 0
i = 0
ans = 0
while maisuu+X[i][1] <= N:
    ans += X[i][0]*X[i][1]
    maisuu += X[i][1]
    i += 1

ans += X[i][0]*(N-maisuu)

print(ans)

### FIXED CODE ###

import collections

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

c = collections.Counter(A)
values,counts = zip(*c.most_common())
D=[]
for i in range(len(counts)):
    D.append([counts[i],values[i]])
for i in range(M):
    D.append(BC[i])
D=sorted(D,key=lambda x:x[1], reverse=True)

t=0
i=0
ans=0
while t<N:
    if D[i][0]+t<=N:
        ans+=D[i][1]*D[i][0]
        t+=D[i][0]
        i+=1
    else:
        ans+=D[i][1]*(N-t)
        t+=N-t
print(ans)
### BUGGY CODE ###

s=input()
t=len(s)
ans=0
ruiseki=[int(s[-1]) for i in range(t)]
for i in range(1,t):
    ruiseki[i]=(ruiseki[i-1]+int(s[-1-i])*pow(10,i,2019))%2019

ans+=ruiseki.count(0)
for i in range(2019):
    o=ruiseki.count(i)
    ans+=o*(o-1)//2
print(ans)




### FIXED CODE ###

s=input()
t=len(s)
ans=0
ruiseki=[int(s[-1]) for i in range(t)]
for i in range(1,t):
    ruiseki[i]=(ruiseki[i-1]+int(s[-1-i])*pow(10,i,2019))%2019
from collections import Counter
ans+=ruiseki.count(0)
C=Counter(ruiseki)
for x in C.values():
    ans+=x*(x-1)//2
print(ans)