Harryxun/stf_run huggingface dataset:
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)


k=input()
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    d=gcd(i,j)
    for l in range(1,k+1):
      if d!=1:
        ans+=gcd(d,l)
      else:
        ans+=1


print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)


def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)


k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    d=gcd(i,j)
    for l in range(1,k+1):
      if d!=1:
        ans+=gcd(d,l)
      else:
        ans+=1


print(ans)
N, M = list(map(int, input().split()))
s, c = [], []
mapSC = {}
for _ in range(M):
    si, ci = list(map(int, input().split()))
    s.append(si)
    c.append(ci)
    if si not in mapSC:
        mapSC[si] = ci
    else:
        if mapSC[si] != ci:
            print("-1")
            exit(0)

if len(mapSC) > N:
    print("-1")
    exit(0)

if N > 1 and s[0] == 0:
    print("-1")
    exit(0)

if s == 1:
    rb, re = 0, 10
elif s == 2:
    rb, re = 10, 100
else:
    rb, re = 100, 1000

ans = -1
for v in range(rb, re):
    sv = "{}".format(v)
    lf = []
    for i in range(M):
        lf.append(int(sv[s[i] - 1]) == int(c[i]))
    if all(lf):
        ans = v
        break
    # print(sv, lf, all(lf))

print(ans)

### FIXED CODE ###

N, M = list(map(int, input().split()))
s, c = [], []
mapSC = {}
for _ in range(M):
    si, ci = list(map(int, input().split()))
    s.append(si)
    c.append(ci)
    if si not in mapSC:
        mapSC[si] = ci
    else:
        if mapSC[si] != ci:
            print("-1")
            exit(0)

if len(mapSC) > N:
    print("-1")
    exit(0)

# if N > 1 and s[0] == 0:
#     print("-1")
#     exit(0)

if N == 1:
    rb, re = 0, 10
elif N == 2:
    rb, re = 10, 100
else:
    rb, re = 100, 1000

ans = -1
for v in range(rb, re):
    sv = "{}".format(v)
    lf = []
    for i in range(M):
        lf.append(int(sv[s[i] - 1]) == int(c[i]))
    if all(lf):
        ans = v
        break
    # print(sv, lf, all(lf))

print(ans)
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
ans=""
ans_1=0
for S in s:
    if s.count(S)-t.count(S)>0:
        ans=S
        if s.count(S)-t.count(S)>ans:
            ans_1=s.count(S)-t.count(S)
if ans_1>=0:
    print(ans)
else:
    print("0")

### FIXED CODE ###

N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
def ans1(x):
    return s.count(x)-t.count(x)
ans2=0
ans_1=0
for S in s:
    if ans1(S)>0 and ans1(S)>ans2:
            ans2=ans1(S)
if ans2>=0:
    print(ans2)
else:
    print("0")
n , m = map(int, input().split(' '))
s = [0,2,5,5,4,5,6,3,7,6]
a = list(map(int, input().split(' ')))
r = []
for i in range(len(a)):
    r.append([s[a[i]],a[i]])
r.sort()
d = [0]
for i in range(n):
    d.append(-1)
#i 本　マッチを使う
for i in range(n+1):
    j = 0
    while j < len(a):
        if d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1
result = []
a.sort(reverse = True)
while n > 0:
    j = 0
    while j < len(a):
        if d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
        else:
            j += 1
            
print(''.join(list(map(str, result))))

### FIXED CODE ###

n , m = map(int, input().split(' '))
s = [0,2,5,5,4,5,6,3,7,6]
a = list(map(int, input().split(' ')))
r = []
for i in range(len(a)):
    r.append([s[a[i]],a[i]])
r.sort()
d = [-1]*(n+1)
d[0] = 0
for i in range(1,n+1):
    j = 0
    while j < len(a):
        if i-s[r[j][1]] < 0:
            j += 1
        elif d[i-s[r[j][1]]] >= 0:
            d[i] = d[i-s[r[j][1]]] +1
            break
        else:
            j+= 1
result = []
a.sort(reverse = True)
while n > 0:
    j = 0
    while j < len(a):
        if n < s[a[j]]:
            j += 1
        elif d[n-s[a[j]]] +1 == d[n]:
            result.append(a[j])
            n -= s[a[j]]
            break
        else:
            j += 1
print(''.join(list(map(str, result))))
s1,s2,s3 = map(int,input().split())
l = []
l += [s1,s2,s3]
print(l.count(1))

### FIXED CODE ###

s1 = input()
print(s1.count('1'))
#3
#8 12 40
n=int(input())
ai=list(map(int(),input.split()))
b=[]
for a in ai:
  count =0
  while a%2==0 :
    count+=1
    a/=2
  b.append(count)
print(min(b))

### FIXED CODE ###

#3
#8 12 40
n=int(input())
ai=list(map(int,input().split()))
b=[]
for a in ai:
  count =0
  while a%2==0 :
    count+=1
    a/=2
  b.append(count)
print(min(b))
def main():
    N, K = map(int, input().split())
    P = list(map(func,map(int, input().split())))
    C = list(map(int, input().split()))
    ans = -float('inf')
    for si in range(N):
        x = si
        tot = 0
        S = []
        while True:
            x = P[x]
            S.append(C[x])
            tot += C[x]
            if x == si:
                break
        l = len(S)
        t = 0
        for i in range(l):
            t += S[i]
            if i + 1 > K:
                break
            now = t
            if tot > 0:
                e = (K-(i+1)) // l
                now += tot*e
            ans = max(ans, now)

    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

def func(x):
    return x - 1
def main():
    N, K = map(int, input().split())
    P = list(map(func,map(int, input().split())))
    C = list(map(int, input().split()))
    ans = -float('inf')
    for si in range(N):
        x = si
        tot = 0
        S = []
        while True:
            x = P[x]
            S.append(C[x])
            tot += C[x]
            if x == si:
                break
        l = len(S)
        t = 0
        for i in range(l):
            t += S[i]
            if i + 1 > K:
                break
            now = t
            if tot > 0:
                e = (K-(i+1)) // l
                now += tot*e
            ans = max(ans, now)

    print(ans)


if __name__ == "__main__":
    main()
from math import gcd
n = int(input())
li = []
for i in range(n):
    s = input()
    if '.' in s:
        a, b = s.split('.')
        t = 10 ** len(b)
        li.append((int(a) * t + int(b), t))
    else:
        li.append((int(s), 1))
p = [[0] * 20 for _ in range(24)]
cnt = 0
for i in range(n):
    x, y = li[i]
    g = gcd(x, y)
    x //= g
    y //= g
    if y == 1:
        cnt += 1
    li[i] = x
    a1, b1 = 0, 0
    while x % 2 == 0:
        a1 += 1
        x //= 2
    while x % 5 == 0:
        b1 += 1
        x //= 5
    a2, b2 = 0, 0
    while y % 2 == 0:
        a2 += 1
        y //= 2
    while y % 5 == 0:
        b2 += 1
        y //= 5
    p[a1 - a2 + 9][b1 - b2 + 9] += 1
ans = 0
for i in range(0, 24):
    for j in range(0, 20):
        for a in range(18 - i, 24):
            for b in range(18 - j, 20):
                if p[i][j] * p[a][b]:
                    a
                ans += p[i][j] * p[a][b]
print((ans - cnt) // 2)


### FIXED CODE ###

from math import gcd
n = int(input())
li = []
for i in range(n):
    s = input()
    if '.' in s:
        a, b = s.split('.')
        t = 10 ** len(b)
        li.append((int(a) * t + int(b), t))
    else:
        li.append((int(s), 1))
p = [[0] * 35 for _ in range(35)]
cnt = 0
for i in range(n):
    x, y = li[i]
    g = gcd(x, y)
    x //= g
    y //= g
    if y == 1:
        cnt += 1
    li[i] = x
    a1, b1 = 0, 0
    while x % 2 == 0:
        a1 += 1
        x //= 2
    while x % 5 == 0:
        b1 += 1
        x //= 5
    a2, b2 = 0, 0
    while y % 2 == 0:
        a2 += 1
        y //= 2
    while y % 5 == 0:
        b2 += 1
        y //= 5
    p[a1 - a2 + 9][b1 - b2 + 9] += 1
ans = 0
for i in range(0, 35):
    for j in range(0, 35):
        for a in range(max(0, 18 - i), 35):
            for b in range(max(0, 18 - j), 35):
                ans += p[i][j] * p[a][b]
print((ans - cnt) // 2)
import sys
N, Q = [int(i) for i in input().split()]
tree = {i:[] for i in range(1,N+1)}
cost_ls = {i:0 for i in range(1,N+1)}
for i in range(N-1):
    a, b = [int(j) for j in sys.stdin.readline().split()]
    tree[a].append(b)
    tree[b].append(a)

yet = set()
def plus(node, _from):
    yet.add(node)
    #cost_ls[node] += num
    for child in tree[node]:
        if child == _from:
            continue
        cost_ls[child] += cost_ls[node]
        plus(child, node)

for i in range(Q):
    p, x = [int(j) for j in sys.stdin.readline().split()]
    cost_ls[p] += x

plus(1, 0)

print(' '.join(str(cost_ls[i]) for i in range(1,N+1)))

### FIXED CODE ###

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())
V = {i: [] for i in range(1, N + 1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1, N + 1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)


propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1, N + 1)))
word = input():
if word == 'SSS':
  print(0)
if word == 'SSR':
  print(1)
if word == 'SRS':
  print(1)
if word == 'RSS':
  print(1)
if word == 'SRR':
  print(2)
if word == 'RRS':
  print(2)
if word == 'RSR':
  print(1)
if word == 'RRR':
  print(3)

### FIXED CODE ###

word = input()
if word == 'SSS':
  print(0)
if word == 'SSR':
  print(1)
if word == 'SRS':
  print(1)
if word == 'RSS':
  print(1)
if word == 'SRR':
  print(2)
if word == 'RRS':
  print(2)
if word == 'RSR':
  print(1)
if word == 'RRR':
  print(3)
a = input()
b=int(a[0:2])
c=int(a[2:4])
if 0<b<=12 & 0<c<=12:
    print('AMBIGUOUS')
elif 0<b<=12 & (c>12 or C ==0) :
    print('MMYY') 
elif (b>12 or b==0) & 0<c<=12:
    print('YYMM')
else:
    print('NA')

### FIXED CODE ###

a = input()
b=int(a[0:2])
c=int(a[2:4])
if 1<=b<=12 and 1<=c<=12:
    print('AMBIGUOUS')
elif 1<=b<=12 :
    print('MMYY') 
elif 1<=c<=12:
    print('YYMM')
else:
    print('NA')
S = input()
T = input()

ans = "No"
if len(S)+1 == len(T):
	if T.startswith(S) is True:
      ans = "Yes"
print(ans)

### FIXED CODE ###

S = input()
T = input()
 
ans = "No"
if len(S)+1 == len(T):
  if T.startswith(S) is True:
    ans = "Yes"
print(ans)
N=int(input())
A=[int(input()) for _ in range(N)]

A.sort(reverse=True)

ans=0
while A!=[]:
  ans+=abs(A.pop(0)-A[-1])
  A[::-1]
  
print(ans)

### FIXED CODE ###

N=int(input())
A=[int(input()) for _ in range(N)]

A.sort(reverse=True)
if len(A)%2==0:
  print(A[len(A)//2-1]-A[len(A)//2]+2*sum(A[:len(A)//2-1])-2*sum(A[len(A)//2+1:]))
else:
  tmp1=-A[len(A)//2]-A[len(A)//2+1]+2*sum(A[:len(A)//2])-2*sum(A[len(A)//2+2:])
  tmp2=A[len(A)//2-1]+A[len(A)//2]+2*sum(A[:len(A)//2-1])-2*sum(A[len(A)//2+1:])
  print(tmp1 if tmp1>tmp2 else tmp2)
x=int(input())
for a in range(200):
    for b in range(-200,200):
        if a**5-b**5==:
            print(a,b)
            exit()



### FIXED CODE ###

x=int(input())
ma=200
for i in range(ma):
    for j in range(-ma,ma):
        if (i**5 - j**5) ==x:
            print(i,j)
            exit()
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;

const int MAXN = 200005;

int N, K, L, u, v, visited[2][MAXN], cnt[2] = {1, 2};
vector<int> adjList[2][MAXN];

map<ii,int> m;

void dfs(int id, int node) {
    if (visited[id][node]) {
        return;
    } else {
        visited[id][node] = cnt[id];

        for (int i = 0; i < adjList[id][node].size(); i++) {
            int neighbor = adjList[id][node][i];

            dfs(id, neighbor);
        }
    }
}

int main() {

    scanf("%d%d%d", &N, &K, &L);
    for (int i = 0; i < K; i++) {
        scanf("%d%d", &u, &v);

        adjList[0][u].push_back(v);
        adjList[0][v].push_back(u);
    }

    for (int i = 0; i < L; i++) {
        scanf("%d%d", &u, &v);

        adjList[1][u].push_back(v);
        adjList[1][v].push_back(u);
    }

    for (int i = 1; i <= N; i++) {
        if (!visited[0][i]) {
            dfs(0, i); cnt[0] += 2;
        }
        if (!visited[1][i]) {
            dfs(1, i); cnt[1] += 2;
        }
    }

    for (int i = 1; i <= N; i++) {
        m[ii(visited[0][i], visited[1][i])]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << m[ii(visited[0][i], visited[1][i])] << " ";
    }

    return 0;
}

### FIXED CODE ###

T = ["maerd", "remaerd", "esare", "resare"]

s = raw_input()
s = s[::-1]

ans = True
while True:
	if s == "":
		ans = True
		break
	elif s[0] == "m" and len(s) >= len(T[0]) and s[:len(T[0])] == T[0]:
		s = s[len(T[0]):]
	elif s[0] == "r" and len(s) > 2:
		if s[2] == "m" and len(s) >= len(T[1]) and s[:len(T[1])] == T[1]:
			s = s[len(T[1]):]
		elif s[2] == "s" and len(s) >= len(T[3]) and s[:len(T[3])] == T[3]:
			s = s[len(T[3]):]
		else:
			ans = False
			break
	elif s[0] == "e" and len(s) >= len(T[2]) and s[:len(T[2])] == T[2]:
		s = s[len(T[2]):]
	else:
		ans = False
		break

if ans:
	print "YES"
else:
	print "NO"
from collections import defaultdict
from operator import itemgetter

N, X, D = map(int, input().split())
if D < 0:
    D = -D
    X = -X

s = defaultdict(list)
for k in range(N+1):
    p = k * X % D
    q = k * X // D
    a = k * (k - 1) // 2
    b = (N - 1) * k - a + 1
    s[p].append((a + q, b + q))

ans = 0
for v in s.values():
    if not v: continue
    v.sort()
    a, b = v[0]
    for x, y in v[1:]:
        if b < x:
            ans += b - a
            a, b = x, y
        else:
            b = max(b, y)
    ans += b - a

print(ans)


### FIXED CODE ###

from collections import defaultdict
from operator import itemgetter

def solve(N, X, D):
    if D < 0:
        D = -D
        X = -X
    elif D == 0:
        if X == 0:
            return 1
        return N + 1

    s = defaultdict(list)
    for k in range(N+1):
        p = k * X % D
        q = k * X // D
        a = k * (k - 1) // 2
        b = (N - 1) * k - a + 1
        s[p].append((a + q, b + q))

    ans = 0
    for v in s.values():
        if not v: continue
        v.sort()
        a, b = v[0]
        for x, y in v[1:]:
            if b < x:
                ans += b - a
                a, b = x, y
            else:
                b = max(b, y)
        ans += b - a
    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    print(solve(N, X, D))
n=int(input())
a=list(map(int, input().split()))
q=int(input())
results=[]

S=sum(a)

table=[0]*(10**5)

for i in range(n):
    table[a[i]]+=1

for i in range(q):
    b, c=map(int, input().split())
    if table[b]!=0:
        cnt=table[b]
        table[c]+=cnt
        ans=S+(cnt*(c-b))
        results.append(ans)
        table[b]=0
        S=ans
    else:
        results.append(S)

for result in results:
    print(result)

### FIXED CODE ###

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

S=sum(a)

table=[0]*(10**6)

for i in range(n):
    table[a[i]]+=1

for i in range(q):
    b, c=map(int, input().split())
    if table[b]!=0:
        cnt=table[b]
        table[c]+=cnt
        ans=S+(cnt*(c-b))

        print(ans)

        table[b]=0
        S=ans
    else:
        print(S)
s = input()
t = input()
k = t.index(s[0])
t = t[k:]+t[:k]
if s==t:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import sys
s = input()
t = input()
for i in range(len(t)):
    l = t[i:]+t[:i]
    if s==l:
        print("Yes")
        sys.exit()
print("No")
from math import factorial

def comb(n, r):
    if n == 1:
        return 0
    return factorial(n) / factorial(r) / factorial(n - r)

N = int(input())
S = [input() for _ in range(N)]
if N == 1:
    print(0)
    exit()
    
str_dict = {}
for s in S:
    sorted_s = "".join(sorted(s))
    if sorted_s not in str_dict:
        str_dict[sorted_s] = 0
    str_dict[sorted_s] += 1
ans = sum([comb(v, 2) for v in str_dict.values()])
print(int(ans))

### FIXED CODE ###

from math import factorial

def comb(n, r):
    if n == 1:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(input())
S = [input() for _ in range(N)]
str_dict = {}
for s in S:
    sorted_s = "".join(sorted(s))
    if sorted_s not in str_dict:
        str_dict[sorted_s] = 0
    str_dict[sorted_s] += 1
ans = sum([comb(v, 2) for v in str_dict.values()])
print(int(ans))
n = input()
lst = sorted([int(x) for x in input().split()], reverse=True)
alice = 0
bob = 0
for i in range(len(lst)):
    if i%2:
        bob += lst[I]
    else:
        alice += lst[i]
print(alice-bob)

### FIXED CODE ###

n = input()
lst = sorted([int(x) for x in input().split()], reverse=True)
alice = 0
bob = 0
for i in range(len(lst)):
    if i%2:
        bob += lst[i]
    else:
        alice += lst[i]
print(alice-bob)
N = int(input())
x = list(input())[::-1]
num = 0
nump = 0
numm = 0
pop_num = 0
for i in range(N):
    if x[i] == "1":
        pop_num += 1
for i in range(N):
    if x[i] == "1":
        num += pow(2,i,pop_num)
        num %= pop_num 
        nump += pow(2,i,pop_num+1)
        nump %= pop_num  + 1
        numm += pow(2,i,pop_num - 1)
        numm %= pop_num - 1



def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

x = x[::-1]
def calc(i,depth,n):
    if depth == 0:
        if x[i] == "1":
            tmp = numm
            tmp -=  2 ** (N - i - 1)
            tmp %= (pop_num - 1)
            return calc(i,depth+1,tmp)
        else:
            tmp = nump
            tmp +=  2 ** (N - i - 1)
            tmp %= (pop_num + 1)
            return calc(i,depth+1,tmp)
    else:
        if n == 0: return depth
        if popcnt(n) == 0:
            while True:
                print("A")
        return calc(i,depth+1, n % popcnt(n))
        

for i in range(N):
    print(calc(i,0,0))



### FIXED CODE ###

N = int(input())
x = list(input())[::-1]
num = 0
nump = 0
numm = 0
pop_num = 0
for i in range(N):
        if x[i] == "1":
            pop_num += 1
for i in range(N):
    if x[i] == "1":
        num += pow(2,i,pop_num)
        num %= pop_num 
        nump += pow(2,i,pop_num+1)
        nump %= pop_num  + 1
        if pop_num-1 != 0:
            numm += pow(2,i,pop_num - 1)
            numm %= pop_num - 1



def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

x = x[::-1]
def calc(i,depth,n):
    if depth == 0:
        if x[i] == "1":
            tmp = numm
            if pop_num - 1 != 0:
                tmp -= pow(2,N-i-1,pop_num-1)
                tmp %= (pop_num - 1)
            else:
                return 0
            return calc(i,depth+1,tmp)
        else:
            tmp = nump
            tmp += pow(2,N-i-1,pop_num+1)
            tmp %= (pop_num + 1)
            return calc(i,depth+1,tmp)
    else:
        if n == 0: return depth
        return calc(i,depth+1, n % popcnt(n))
        

for i in range(N):
    print(calc(i,0,0))
doubletCount = 0
    cases = int(input())
    for roll in range(cases):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            doubletCount += 1
        else:
            doubletCount = 0
            
        if doubletCount >= 3:
            print("Yes")
            break
        
        if roll == cases - 1:
            print("No")

### FIXED CODE ###

doubletCount = 0
cases = int(input())
for roll in range(cases):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        doubletCount += 1
    else:
        doubletCount = 0
                
    if doubletCount >= 3:
        print("Yes")
        break
            
    if roll == cases - 1:
        print("No")
#!/usr/bin/env python3
import sys
from collections import Counter
import numpy as np
sys.setrecursionlimit(10**8)
MOD = 1000000007  # type: int


def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []

    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1

    return prime_list


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

    primes = eratosthenes_sieve(10**3)

    def factorial(n):
        # 試し割りによる素因数分解
        prime_count = Counter()
        for i in primes:
            while n % i == 0:
                n /= i
                prime_count[i] += 1
        if n > 1:
            prime_count[int(n)] += 1
        return prime_count

    C = [factorial(a) for a in A]

    K = Counter()
    for c in C:
        for k in c:
            K[k] = max(K[k], c[k])
    # print(K)

    B = [0]*N
    for i in range(N):
        b = Counter()
        for k in K:
            b[k] = K[k] - C[i][k]
        a = 1
        for k in b:
            if b[k] != 0:
                a *= k**b[k]
                a %= MOD
        B[i] = a
    # print(B)
    print(sum(B) % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter
import math
MOD = 1000000007  # type: int


def factorial(n):
    prime_count = Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % MOD
    elif y % 2 == 0:
        return power(x, y//2)**2 % MOD
    else:
        return power(x, y//2)**2 * x % MOD


def div(a, b):
    return (a * power(b, MOD-2)) % MOD


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

    lcm = Counter()
    for a in A:
        c = factorial(a)
        for k in c:
            lcm[k] = max(c[k], lcm[k])
    # print(lcm)

    LCM = 1
    for k, v in lcm.items():
        LCM *= power(k, v)
        LCM %= MOD
    # print(LCM)

    tot = 0
    for a in A:
        tot += div(LCM, a)
    print(tot % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()