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

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
S = input()
s1 = S[:n];s2 = S[n:][::-1]
C1 = collections.Counter()
C2 = collections.Counter()
for bit in range(2**n):
  tmp10 = ""
  tmp11 = ""
  tmp20 = ""
  tmp21 = ""
  for i in range(n):
    if bit >> i & 1:
      tmp10 += s1[i]
      tmp20 += s2[i]
    else:
      tmp11 += s1[i]
      tmp21 += s2[i]
  C1[(tmp10,tmp11)] += 1
  C2[(tmp21,tmp20)] += 1
for key,item in C1.items():
  ans += C2[key] * item 
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
S = input()
s1 = S[:n];s2 = S[n:][::-1]
C1 = collections.Counter()
C2 = collections.Counter()
for bit in range(2**n):
  tmp10 = ""
  tmp11 = ""
  tmp20 = ""
  tmp21 = ""
  for i in range(n):
    if bit >> i & 1:
      tmp10 += s1[i]
      tmp20 += s2[i]
    else:
      tmp11 += s1[i]
      tmp21 += s2[i]
  C1[(tmp10,tmp11)] += 1
  C2[(tmp21,tmp20)] += 1
for key,item in C1.items():
  ans += C2[key] * item 
print(ans)
### BUGGY CODE ###

U = 2*10**6+2
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
ans = 0
r1, c1, r2, c2 = map(int, input().split())
for i in range(c1, c2+1):
  ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  ans %= MOD
print(ans)

### FIXED CODE ###

U = 2*10**6+2
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
ans = 0
r1, c1, r2, c2 = map(int, input().split())
for i in range(c1, c2+1):
  ans += comb(i+r2+1, i+1) - comb(i+r1, i+1)
  ans %= MOD
print(ans)
### BUGGY CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 0
    for i in range(N):
        for j in range(i + A[i] + 1, N):
            if A[i] + A[j] == j - i:
                answer += 1
    print(answer)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = defaultdict(list)
    R = defaultdict(list)
    for i in range(N):
        L[A[i] + i].append(i)
        R[i - A[i]].append(i)
    K = list(L.keys())

    answer = 0
    for k in K:
        l = len(L[k])
        r = len(R[k])
        answer += l * r
    print(answer)


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

import sys
def f(j):
  if j==0:return 0
  if dp[j]!=-1:return dp[j]
  f_k=[f(j-l-1)+abs(h[j]-h[j-l-1]) for l in range(k) if j-l-1>=0]
  dp[j]=min(f_k)
  return dp[j]
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[-1]*n
sys.setrecursionlimit(1000000000)
print(f(n-1))

### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())


n,k = inpl()
h = inpl()
dp = [INF] * (n)
dp[0] = 0
for i in range(min(n,k)):
    dp[i] = abs(h[i] - h[0])
for i in range(n - k):
    option=[dp[i+j]+abs(h[i+k]-h[i+j]) for j in range(k)]
    dp[i + k] = min(option)
print(dp[n - 1])
### BUGGY CODE ###

import copy

N = int(input())

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

max_a = max(A)

for i in range(N):
    max_l=0
    max_R=0
    if(A[:i]!=[]):
        max_l = max(A[:i])
    if(A[i+1:]!=[]):
        max_r = max(A[i+1:])
    print(max(max_r,max_l))


### FIXED CODE ###

import copy

N = int(input())

A = [int(input()) for _ in range(N)]
B = sorted(A)
max_1 = B[-1]
max_2 = B[-2]

for i in range(N):
    if(A[i]==max_1):
        print(max_2)
    else:
        print(max_1)
### BUGGY CODE ###

import bisect
N, M = map(int, input().split())
a = [None for i in range(2 * M)]
number = [None for i in range(2 * M)]
flag = 0
for i in range(M):
    A, B = map(int, input().split())
    a[2*i] = [A, B]
    a[2*i+1] = [B, A]
    number[2*i]
    number[2*i+1]
a.sort()
b = a[:]
b.reverse()
one = []
two = []
for i in range(M):
    if a[i][0] == 1:
        one.append(a[i][1])
    else:
        break

for i in range(M):
    if b[i][0] == N:
        two.append(b[i][1])
    else:
        break
def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr
if len(intersect_list(one, two)) != 0:
    print("POSSIBLE")

else:
    print("IMPOSSIBLE")


### FIXED CODE ###

import sys

N, M = map(int, input().split())
ship = [[] for i in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    ship[a].append(b)
    ship[b].append(a)

flag = 0
for i in ship[1]:
    if N in ship[i]:
        flag = 1
if flag == 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

def main():
    inputs = input().split()
    inputs = [int(i) for i in inputs]

    a = inputs[0]
    b = inputs[1]

    max_n = max([a, b])

    kouyaku = []

    for n in range(1, int(max_n / 2) + 1):
        if a % n == 0 and b % n == 0:
            kouyaku.append(n)

    so = [1]
    for i in kouyaku:
        if i == 1: continue

        f = True
        for j in kouyaku:
            if j == 1 or i < j: continue
            if i != j and i % j == 0:
                f = False
                break
        if f is True:
            so.append(i)

    print(len(so))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import math


def main():
    inputs = input().split()
    inputs = [int(i) for i in inputs]

    a = inputs[0]
    b = inputs[1]

    g = n = gcd(a, b)
    d = {}

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

    if n != 1:
        d[n] = n

    print(len(d) + 1)


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


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

M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = range(0, p * 10, p) if c == '?' else (p * int(c),)
    a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])


### FIXED CODE ###

M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = range(10) if c == '?' else (int(c),)
    a = [sum(a[(i - p * j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])
### BUGGY CODE ###

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

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

from collections import defaultdict
D = [defaultdict(int) for _ in range(N)]
cmnd = defaultdict(int)

for i,a in enumerate(A):
    for n in range(2, int(a**0.5)+1):
        while a % n == 0:
            D[i][n] += 1
            a //= n
    if a > 1: D[i][a] += 1
    for k,v in D[i].items():
        cmnd[k] = max(cmnd[k], v)

ans = Mint()
for i in range(N):
    tmp = Mint(1)
    for k,v in cmnd.items():
        tmp *= k**(v-D[i][k])
    ans += tmp

print(ans)

### FIXED CODE ###

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

MOD=10**9+7
def gcd(a,b):
    while b: a,b=b,a%b
    return a
def lcm(a,b): return a*b//gcd(a,b)

LCM=A[:]
num=N
while num>1:
    for i in range(1,num,2):
        LCM[i//2]=lcm(LCM[i-1],LCM[i])
    if num&1:
        LCM[num//2]=LCM[num-1]
    num=(num+1)//2

ans=0
l=LCM[0]%MOD
for a in A:
    ans+=l*pow(a,MOD-2,MOD)
    ans%=MOD

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

N = int(input())

s = []
s_ap = s.append

for i in range(N):
    s_ap("".join(sorted(input())))

s.sort()

s_set = set(s)

result = 0

for _ in s_set:
    cnt = s.count(_)
    result += int(cnt * (cnt - 1) / 2)

print(result)

### FIXED CODE ###

from collections import Counter

N = int(input())

s = []
s_ap = s.append

for i in range(N):
    s_ap("".join(sorted(input())))

result = 0

for i in Counter(s).values():
    if not i == 1:
        result += int(i * (i - 1) / 2)
        
print(result)
### BUGGY CODE ###

A , B , C , K = map(int,input().split())
s = 0
for i in range(K):
    if A >= 1:
        s += 1
        A -= 1
    elif B >= 1:
        s += 0
        B -= 1
    elif C >= 1:
        s -= 1
        C -= 1

print(s)

### FIXED CODE ###

A , B , C , K = map(int,input().split())

s = 0

mn = min(A, K)
s += mn 
K -= mn

mn = min(B, K)
K -= mn

mn = min(C, K)
s -=mn
K -= mn

print(s)
### BUGGY CODE ###

K=int(input())

result=[]
count=0
cnt=0
def gcd(a,b):
  for i in range(200):
    if b!=0:
      a,b=b,a%b
    if b==0:
      break
  return a

 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      cnt+=gcd(gcd(i,j),k)


print(cnt)


### FIXED CODE ###

from math import gcd
K=int(input())

result=[]
count=0
cnt=0
# def gcd(a,b):
#   while b!=0:
#     a,b=b,a%b
#   return a

 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      cnt+=gcd(gcd(i,j),k)


print(cnt)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
q = int(input())
for _ in range(q):
  b,c = map(int,input().split())
  for n,i in enumerate(a):
    if i == b:
      a[n] = c
  print(sum(a))

### FIXED CODE ###

from collections import Counter

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

C = Counter(a)
s = sum(a)

for _ in range(q):
  b,c = map(int,input().split())
  s = s - b*C[b] + c*C[b]
  C[c] += C[b]
  C[b] = 0
  print(s)
### BUGGY CODE ###

N = int(input())
T = list(map(int,input().split()))
T.sort()
ANSL = []
for i in range(len(T)):
    S = []
    for j in range(len(T)):
        S.append(T[j])
    S.pop(i)
    ANS = 0
    while True:
        S.sort()
        LIS = []
        if S[0] == 1:
            ANS += 1
            break
        elif len(S) == 1:
            ANS += S[0]
            break
        else:
            LIS.append(S[0])
            for k in range(len(S)-1):
                if S[k+1] % S[k] == 0:
                    continue
                else:
                    LIS.append(S[k+1] % S[k])
        S = LIS
    ANSL.append(ANS)
print(max(ANSL))


### FIXED CODE ###

import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if len(T) == 2:
    ANS = max(T[0],T[1])
elif F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)
### BUGGY CODE ###

n, y = map(int, input().split())
ans_flg = False
ans_ct = {}

for i in range(n+1):
    for j in range(n-i+1):
        for k in range(n-i-j+1):
            if y == 10000*i + 5000*j + 1000*k and i+j+k == n:
                ans_flg = True
                ans_ct = {"i": i, "j": j, "k": k}
                break

if ans_flg:
    print("{} {} {}".format(ans_ct["i"], ans_ct["j"], ans_ct["k"]))
else:
    print("-1 -1 -1")





### FIXED CODE ###

n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i+1):
        if y == 10000*i + 5000*j + 1000*(n-i-j):
            print(i, j, n-i-j)
            exit()

print("-1 -1 -1")
### BUGGY CODE ###

l, r = map(int, input().split())

if r-l > 2018:
    print(0)

ans = 2018
for i in range(l, r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)

print(ans)

### FIXED CODE ###

l, r = map(int, input().split())
res = 2018

if r-l > 2018:
    print(0)
    exit()
else:
    for i in range(l, r):
        for j in range(i+1, r+1):
            res = min(res, (i*j)%2019)
print(res)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
vals = []
ans = 0
for i in range(1, n+1):
    vals.append(i-a[i-1])
for i in range(n):
    for v in range(n):
        if(i+1+a[i] == vals[v] or i+1+a[i] == vals[v]):
            ans+=1
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
vals = []
mappy = {}
ans = 0
for i in range(n):
    if(i+1-a[i] > 0):
        if(i+1-a[i] in mappy):
            mappy[i+1-a[i]]+=1
        else:
            mappy[i+1-a[i]] =1
for i in range(n):
    if(i+1+a[i]in mappy):
        ans+=mappy[i+1+a[i]]
print(ans)
### BUGGY CODE ###

N=input()
A=map(int,raw_input().split())
B=map(int,raw_input().split())
unmatch=[]
need=0

for i in range(N):
    if A[i]<B[i]:
        unmatch.append(i)
        need+=B[i]-A[i]

Gap=[A[i]-B[i] for i in range(N) if i not in unmatch]
Gap.sort(reverse=True)
Ans=len(unmatch)

while need>0:
    if Ans>=N:
        print "-1"
        exit()
    need-=Gap[Ans-len(unmatch)]
    Ans+=1
print Ans

### FIXED CODE ###

N=input()
A=map(int,raw_input().split())
B=map(int,raw_input().split())
need=0
Ans=0

for a,b in zip(A,B):
    if b>a:
        need+=b-a
        Ans+=1
        
index=0

Gap=[a-b for a,b in zip(A,B)]
Gap.sort(reverse=True)

while need>0:
    if Ans+index>=N:
        break
    need-=Gap[index]
    index+=1
    
if need<=0:
    print Ans+index
else:
    print "-1"
### BUGGY CODE ###

def main():
    mn = int(input())
    j = [int(x) for x in input().split()]
    for x in range(1, mn+1):
        print(j.count(x))


main()

### FIXED CODE ###

N = int(input())
from collections import Counter as C
l = dict(C((int(x) for x in input().split())))
for x in range(1,N+1):
    print(l.get(x,0))
### BUGGY CODE ###

from operator import*
from functools import*
input()
l = map(int, input().split())
n = reduce(mul, l)
if n > 10**18:
    print(-1)
else:
    print(n)

### FIXED CODE ###

input()
l = map(int, input().split())

n = 1
lim = 10**18
for e in l:
    n *= e
    if n > lim:
        print(0 if 0 in l else -1)
        break
else:
    print(n)
### BUGGY CODE ###

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))
    if t[i] > tmax:
        tmax = t[i]

c_timeline = [[0 for _ in range(C)] for _ in range(2*tmax + 1)]
for Si, Ti, Ci in zip(s,t,c):
    for j in range(2*Si-1, 2*Ti+1):
        c_timeline[j][Ci-1] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)


### FIXED CODE ###

N, C = list(map(int, input().split()))
tmax = 0
s = [0 for _ in range(N)]
t = [0 for _ in range(N)]
c = [0 for _ in range(N)]
for i in range(N):
    s[i], t[i], c[i] = list(map(int, input().split()))

tmax = max(t)
c_timeline = [[0]*C for _ in range(2 * tmax + 1)]
for i in range(N):
    S = s[i]
    T = t[i]
    channel = c[i] - 1
    for j in range(2 * S - 1, 2 * T + 1):
        c_timeline[j][channel] = 1

rokuga = 0
for timeline in c_timeline:
    time = sum(timeline)
    if rokuga < time:
        rokuga = time

print(rokuga)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from math import sqrt,ceil,log10

n = int(input())

nsr = sqrt(n)

for i in range(ceil(nsr),n+1):
    if n%i==0:
        ret = ceil(log10(i))
        if 10**ret==int(i):
            print(ret+1)
        else:
            print(ret)
        exit()


### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())

def cntd(x):
    digits = 0

    while x/10>0:
        x = x//10
        digits += 1
    return digits

ans = cntd(n)

a = 1
while a*a<=n:
    if n%a!=0:
        a += 1
        continue

    b = n//a
    cur = max(cntd(a), cntd(b))
    if ans>cur:
        ans = cur
    a += 1

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

H, W = map(int, input().split())
map = [list(input()) for _ in range(H)]
from collections import deque

que = deque()
seen = [[-1]*W for _ in range(H)]
max = 0

for i in range(H):
    for j in range(W):
        if map[i][j] == "#":
            que.append([i,j])
            seen[i][j] = 0

while que:
    y, x = que.popleft()
    for dy, dx in ([0,1],[0,-1],[1,0],[-1,0]):
        ny = y + dy
        nx = x + dx
        if 0<=ny<H and 0<=nx<W and seen[ny][nx]==-1:
            seen[ny][nx] = seen[y][x] + 1
            que.append([ny,nx])
            if max < seen[ny][nx]:
                max = seen[ny][nx]

print(max)


### FIXED CODE ###

H, W = map(int, input().split())
map = [list(input()) for _ in range(H)]
from collections import deque

que = deque()
seen = [[-1]*W for _ in range(H)]
max = 0



for i in range(H):
    for j in range(W):
        if map[i][j] == "#":
            que.append([i,j])
            seen[i][j] = 0

while que:
    #print(que)
    y, x = que.popleft()
    for dy, dx in ([0,1],[0,-1],[1,0],[-1,0]):
        ny = y + dy
        nx = x + dx
        if 0<=ny<H and 0<=nx<W and seen[ny][nx]==-1:
            seen[ny][nx] = seen[y][x] + 1
            que.append([ny,nx])
            if max < seen[ny][nx]:
                max = seen[ny][nx]

print(max)
### BUGGY CODE ###

def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        r = x % y
        x = y
        y = r
    return y
 
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10 ** 9 + 7
 
if N == 1:
    print(1)
    exit()
div = gcd(a_list[0], a_list[1])
lcm = (a_list[0] * a_list[1]) // div
 
for i in range(2, N):
    div = gcd(lcm, a_list[i])
    lcm = (lcm * a_list[i]) // div
    
ans = 0
for i in range(N):
    ans = (ans + lcm//a_list[i]) % MOD
 
print(ans)

### FIXED CODE ###

from functools import reduce

def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        r = x % y
        x = y
        y = r
    return y

def inv(x):
    return pow(x, MOD-2, MOD)

def lcm(a, b):
    return a * b // gcd(a, b)

def lcm_list(l:list):
    return reduce(lcm, l, 1)
  
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10 ** 9 + 7

num = lcm_list(a_list) % MOD
ans = 0
for a in a_list:
    ans += (num * pow(a, MOD-2, MOD)) % MOD

print(ans%MOD)
### BUGGY CODE ###

from itertools import permutations
import sys


input = sys.stdin.readline


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

dest = [x-1 for x in map(int, input().split())]


inf = float('inf')
mat = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    mat[a-1][b-1] = mat[b-1][a-1] = c


for i in range(N):
    for j in range(N):
        for k in range(N):
            mat[j][k] = min(mat[j][k], mat[j][i]+mat[i][k])


ans = inf
for l in permutations(dest):
    tmp = 0
    for u, v in zip(l, l[1:]):
        tmp += mat[u][v]
    ans = min(ans, tmp)

print(ans)


### FIXED CODE ###

from itertools import permutations
import sys


input = sys.stdin.readline


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

dest = [x-1 for x in map(int, input().split())]


inf = float('inf')
mat = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    mat[a-1][b-1] = mat[b-1][a-1] = c


for i in range(N):
    for j in range(N):
        for k in range(N):
            mat[j][k] = min(mat[j][k], mat[j][i]+mat[i][k])


ans = inf
for l in permutations(dest):
    tmp = 0
    for u, v in zip(l, l[1:]):
        tmp += mat[u][v]
    ans = min(ans, tmp)

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

import numpy as np

N = int(input())

ans = 0

for i in range(1, N+1):
	ans += np.sum(np.arange(i, N+1, i))

print(ans)

### FIXED CODE ###

import numpy as np

N = int(input())

ans = 0

for i in range(1, N+1):
	n = int(N/i)
	ans += n * (n + 1) / 2 * i

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

s = list(input())
q = int(input())

for i in range(q):
    t = input()
    if t == "1":
        s.reverse()
    else:
        t2, f, c = t.split()
        if f == "1":
            s.insert(0, c)
        elif f == "2":
            s.append(c)
print("".join(s))


### FIXED CODE ###

s = input()
q = int(input())

is_reverse = False
front_queue = []
back_queue = []
for i in range(q):
    t = input()
    if t == "1":
        is_reverse = not is_reverse
    else:
        t2, f, c = t.split()
        if (f == "1" and not is_reverse) or (f == "2" and is_reverse):
            front_queue.append(c)
        else:
            back_queue.append(c)

result = ""
if is_reverse:
    result = "".join(reversed(back_queue)) + s[::-1] + "".join(front_queue)
else:
    result = "".join(reversed(front_queue)) + s + "".join(back_queue)
print(result)