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

n = int(input())
S = input()

count = 0

for i  in range(n-2):
	for j in range(i+1, n-1):
		for k in range(j+1, n):
			if S[i] != S[j] and S[j] != S[k] and S[i] != S[k] and (j-i) != (k-j):
				count += 1

print(count)


### FIXED CODE ###

n = int(input())
S_list = list(input())

rsum = 0
gsum = 0
bsum = 0

for s in S_list:
	if s == "R":
		rsum += 1
	elif s == "G":
		gsum += 1
	elif s == "B":
		bsum += 1

sum = rsum * gsum * bsum

for i in range(n-2):
	p = (n-i-1) // 2
	for j in range(1,p+1):
		if S_list[i] != S_list[i+j] and S_list[i+2*j]  != S_list[i+j] and S_list[i] != S_list[i+2*j]:
			sum -= 1

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

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

for i in range(N):
	Xwithout = X[:i]+X[i+1:]
	Xwithout.sort()
	print(Xwithout[N//2-1])

### FIXED CODE ###

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

mylist = sorted(X)
for i in range(N):
	ans = mylist[N//2-1]
	if X[i] > ans:
		print(ans)
	else:
		print(mylist[N//2])
### BUGGY CODE ###

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

x=x[::-1]

ans=0
for i in range(N):
    if x[i][0]%x[i][1]!=0:
        cnt=x[i][1]-x[i][0]%x[i][1]
        ans+=cnt
        for j in range(i+1,N):
            x[j][0]+=cnt
    cnt=0
print(ans)

### FIXED CODE ###

N=int(input())
r=[]
bi=[]
for i in range(N):
    a,b=map(int,input().split())
    bi.append(b)
    if a%b==0:
        r.append(0)
    else:
        r.append(b-a%b)
push=0
bi=bi[::-1]
r=r[::-1]
for i in range(N):
    if i==0:
        push=r[i]
    else:
        push+=(r[i]-push)%bi[i]
print(push)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)
    a = []
    b = []
    for i in range(len(A)):
        if s % 2 != 0:
            if sum(a) >= (s // 2) - 1 or i == N-1:
                b.append(A[i])
            else:
                a.append(A[i])
        else:
            if sum(a) >= (s // 2) or i == N-1:
                b.append(A[i])
            else:
                a.append(A[i])
    ans1 = abs(sum(a)-sum(b))
    ans2 = abs(sum(a[:-1])-sum(b+[a[-1]]))
    print(min(ans1, ans2))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)
    a = 0
    b = 0
    tmp = []
    for i in range(len(A)):
        if s % 2 != 0:
            if a >= (s // 2) - 1 or i == N-1:
                b += A[i]
            else:
                a += A[i]
                tmp.append(A[i])
        else:
            if a >= (s // 2) or i == N-1:
                b += A[i]
            else:
                a += A[i]
                tmp.append(A[i])
    ans1 = abs(a-b)
    ans2 = abs((a-tmp[-1]) - (b+tmp[-1]))
    print(min(ans1, ans2))


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

N, K, Q = list(map(int, input().split()))

points = []
for i in range(N):
  points.append(K)

for i in range(Q):
  correct = int(input())
  for j in range(N):
    if j != correct - 1:
      points[j] -= 1

for i in range(N):
  if points[i] <= 0:
    print('No')
  else:
    print('Yes')

### FIXED CODE ###

N, K, Q = list(map(int, input().split()))

points = [K-Q] * N

for i in range(Q):
  A = int(input())
  points[A-1] += 1
  
for i in range(N):
  if points[i] > 0:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

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

ans = 'YES'

for i in range(n):
  for j in range(i+1,n):
    if a[i] == a[j]:
      ans = 'NO'
      break
  else:
    continue
  break

print(ans)

### FIXED CODE ###

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

if len(set(a)) == n:
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
N = int(input())
print(sum([i for i in range(N)]))


### FIXED CODE ###

#!/usr/bin/env python3
N = int(input())
print(int(N*(N-1))//2)
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [-1 for _ in range(W + 1)] # dp[重量の総和]:= 価値の総和
dp[0] = 0

for i in range(N):
  w, v = wv[i]
  for j in range(W, -1, -1):
    if dp[j] >= 0 and j + w <=  W:
      dp[j+w] = max(dp[j+w], dp[j]+v)
      
print(max(dp))

### FIXED CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
 
dp = [-1 for _ in range(W + 1)] # dp[重量の総和]:= 価値の総和
dp[0] = 0
 
for i in range(N):
  w, v = wv[i]
  for j in range(W, -1, -1):
    if dp[j] >= 0 and j + w <=  W:
      dp[j+w] = max(dp[j+w], dp[j]+v)
      
print(max(dp))
### BUGGY CODE ###

import math
from functools import reduce

gcd = lambda *numbers: reduce(math.gcd, numbers)

K = int(input())

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

print(answer)


### FIXED CODE ###

import math
from functools import reduce

gcd = lambda *numbers: reduce(math.gcd, numbers)

K = int(input())

answer = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            answer += gcd(a, b, c)

print(answer)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = list(map(int,input().split()))
a = np.array([],dtype = int)

ans = 0
for i in range(N-1):
    a = np.append(a,1-A[i])
    ans += np.count_nonzero(a==A[i+1])
    a = a + 1

print(ans)

### FIXED CODE ###

import collections

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

L = [A[x]+x+1 for x in range(N)]
R = [x+1-A[x] for x in range(N)]

cL = collections.Counter(L)
cR = collections.Counter(R)

cRlist = list(cR.keys())

for i in range(len(cRlist)):
    tmp = cRlist[i]
    ans += cR.get(tmp,0) * cL.get(tmp,0)
    
print(ans)
### BUGGY CODE ###

from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[N-i-1].append(N - i - 2)
G[X-1].append(Y-1)
G[Y-1].append(X-1)

mind = [[N] * N for _ in range(N)]
todo = deque()
for s in range(N):
    todo.append((0, s))
    done = set()
    while todo:
        d, p = todo.popleft()
        mind[s][p] = min(mind[s][p], d)
        done.add(p)
        for np in G[p]:
            if not np in done:
                todo.append((d + 1, np))

counts = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i + 1, N):
        counts[mind[i][j]-1] += 1
for c in counts:
    print(c)

### FIXED CODE ###

from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[N-i-1].append(N - i - 2)
G[X-1].append(Y-1)
G[Y-1].append(X-1)

mind = [[N] * N for _ in range(N)]
todo = deque()
for s in range(N):
    todo.append((0, s))
    done = set()
    while todo:
        d, p = todo.popleft()
        mind[s][p] = min(mind[s][p], d)
        done.add(p)
        for np in G[p]:
            if not np in done:
                todo.append((d + 1, np))

counts = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i + 1, N):
        counts[mind[i][j]-1] += 1
for c in counts:
    print(c)
### BUGGY CODE ###

n=map(int , input())
arr=list(map(int , input().split()))
p=1000000000000000000
f=0
res=1
for i in arr:
	res=res*i
	if res>p:
		f=1
if res==0:
	print(res)
elif f:
	print(-1)
else:
	print(res)	

### FIXED CODE ###

n=map(int , input())
arr=list(map(int , input().split()))
p=1000000000000000000
f=0
res=1
arr.sort()
for i in arr:
	res=res*i
	if res==0:
		break
	if res>p:
		f=1
		break
if res==0:
	print(res)
elif f:
	print(-1)
else:
	print(res)
### BUGGY CODE ###

s=input()
r=set()
last=0
power=0
d={0:0}
total=0
for i in range(len(s)-1,-1,-1):
    n=int(s[i])*(10**(power))+last
    power+=1
    last=n%2019
    rem=n%2019
    if rem in r:
        d[rem]+=1
        total+=d[rem]-1
    else:
        r.add(rem)
        d[rem]=1
total+=d[0]
print(total)







### FIXED CODE ###

s=input()
r=set()
last=0
power=1
d={0:0}
total=0
rem=0
for i in range(len(s)-1,-1,-1):#handling of 0's as n and rem
    n=int(s[i])*power+rem
    power*=10
    power=power%2019
    rem=n%2019
    if rem in d.keys():
        d[rem]+=1
    else:
        d[rem]=1
    total+=d[rem]-1
print(total+d[0])
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int, input().split()))
res=[]
for a in A:
    tmp=0
    for i in range(1,a+1):
        tmp+=i
    res.append(tmp/a)
cnt=0
for i in range(N):
    if K+i<=N:
        B=sum(res[i:K+i])
        if cnt<B:
            cnt=B
print(cnt)

### FIXED CODE ###

N,K=map(int, input().split())
S=list(map(int, input().split()))
s=sum(S[:K])
dp=[0]*(N-K+1)
dp[0]=s
for i in range(1,N-K+1):
    s=s-S[i-1]+S[i+K-1]
    if s>dp[i-1]:
        dp[i]=s
print((max(dp)+K)/2)
### BUGGY CODE ###

from collections import defaultdict


def longest_common_subsequence(s, t):
    dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    return dp[-1][-1]


def longest_common_subsequence2(s, t):
    dp = [0] * (len(t) + 1)
    for i in range(len(s)):
        si = s[i]
        tmp = dp[:]
        for j in range(len(t)):
            if si == t[j]:
                dp[j + 1] = tmp[j] + 1
            else:
                dp[j + 1] = max(dp[j + 1], dp[j])
    return dp[-1]


def main():
    n = int(input())
    for _ in range(n):
        X, Y = input(), input()
        print(longest_common_subsequence2(X, Y))


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict


def longest_common_subsequence(s, t):
    dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    return dp[-1][-1]


def longest_common_subsequence2(s, t):
    dp = [0] * (len(t) + 1)
    for i in range(len(s)):
        si = s[i]
        tmp = dp[:]
        for j in range(len(t)):
            if si == t[j]:
                dp[j + 1] = tmp[j] + 1
            elif dp[j + 1] < dp[j]:
                dp[j + 1] = dp[j]
    return dp[-1]


def main():
    n = int(input())
    for _ in range(n):
        X, Y = input(), input()
        print(longest_common_subsequence2(X, Y))


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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
f = []
m = 0
for i in range(n):
  p,q = map(int,readline().split())
  m = max(m,p)
  f.append((p,q))
  
f.sort()
dp = [[0]*(t+m) for i in range(n+1)]

for i,c in enumerate(f):
  a,b = c
  for j in range(t+m):
    if j-a >= t:
      break
    if j < a :
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j],dp[i][j-a]+b)
      
print(max(dp[n]))


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
f = []
m = 0
for i in range(n):
  p,q = map(int,readline().split())
  m = max(m,p)
  f.append((p,q))
  
f.sort()
dp = [[0]*(t+m) for i in range(n+1)]

for i,c in enumerate(f):
  a,b = c
  for j in range(t+m):
    if j < a or j-a >= t:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j],dp[i][j-a]+b)
      
print(max(dp[n]))
### BUGGY CODE ###

import sys
import itertools
n, m, x = map(int, input().split())
C = [0] * n
A = [[0] * m for i in range(n)]


sumlist = [0] * m
for i in range(n):
    books = list(map(int, input().split()))
    C[i] = books[0]
    for j in range(m):
        A[i][j] = books[j + 1]
        sumlist[j] += books[j + 1]

# print(n, m, x)
# print(C)
# print(A)
# print(sumlist)

if min(sumlist) < x:
    print("-1")
    sys.exit(0)

def python_list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

min_cost = sys.maxsize
for comb in itertools.permutations(range(n), n):
    learnlist = [0] * n
    cost = 0
    for i in comb:
        learnlist = python_list_add(learnlist, A[i])
        cost += C[i]
        if min(learnlist) >= x:
            if cost < min_cost:
                min_cost = cost
print(min_cost)


### FIXED CODE ###

import sys
import itertools
n, m, x = map(int, input().split())
C = [0] * n
A = [[0] * m for i in range(n)]

mlist = [0] * m
for i in range(n):
    books = list(map(int, input().split()))
    C[i] = books[0]
    for j in range(m):
        A[i][j] = books[j + 1]

mincost = sys.maxsize
for i in range(2**n):
    sumlist = [0] * m
    currentcost = 0
    for j in range(n):
        if ((i >> j) % 2) == 1:
            for k in range(m):
                sumlist[k] += A[j][k]
            currentcost += C[j]
    if min(sumlist) >= x:
        if currentcost < mincost:
            mincost = currentcost

if mincost == sys.maxsize:
    print("-1")
else:
    print(mincost)
### BUGGY CODE ###

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

    total = 1

    for i in a :
        if i == 0 :
            print(0)
            return
        total *= i

    if total > 1000000000000000000 :
        print(-1)
        return

    print(total)

if __name__ == "__main__" :
    solve()

### FIXED CODE ###

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

    total = 1

    if 0 in a :
        print(0)
        return

    for i in a :
        total *= i

        if total > 10 ** 18 :
            print(-1)
            return

    print(total)

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

import sys

def chmin(a,i,b):
  if a[i] > b:
    a[i] = b
    #print(a)
    return True
  else:
    return False

n,k = map(int,input().split())
h = list( map(int,input().split()))
dp = [sys.maxsize for i in range(n+k)]

for i in range(k):
  h.append(sys.maxsize)
  #dp.append(sys.maxsize)


dp[0] = 0
#print(n,h)
#print(dp)

for i in range(n):
  for j in range(1,k+1):
    #chmin(dp,i, abs(h[i]-h[i-j])+dp[i-j])
    #print(i+j)
    dp[i+j] = min(dp[i+j], abs(h[i]-h[i+j])+dp[i])
    #chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));

#print(dp)   
print(dp[n-1])


### FIXED CODE ###

import sys

def chmin(a,i,b):
  if a[i] > b:
    a[i] = b
    #print(a)
    return True
  else:
    return False

n,k = map(int,input().split())
h = list( map(int,input().split()))
dp = [sys.maxsize for i in range(n)]

dp[0] = 0
#print(n,h)
#print(dp)

for i in range(len(dp)):
  for j in range(k+1):
    if i - j >= 0:
      #chmin(dp,i, abs(h[i]-h[i-j])+dp[i-j])
      dp[i] = min(dp[i], abs(h[i]-h[i-j])+dp[i-j])

#print(dp)   
print(dp[-1])
### BUGGY CODE ###

import bisect
n,q = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l = sorted(l,key = lambda x: x[2])
d = [int(input()) for i in range(q)]

ans = [-1]*q
skip = [-1]*q
for s,t,x in l:
    le = bisect.bisect_left(d,s-x)
    ri = bisect.bisect_left(d,t-x)
    while le < ri:
        if skip[le] == -1:
            ans[le] = x
            skip[le] = ri
            le += 1
        else:
            le = skip[le]

for i in ans:
    print(i)


### FIXED CODE ###

import bisect
n,q = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l = sorted(l,key = lambda x: x[2])
d = [int(input()) for i in range(q)]

ans = [-1]*q
skip = [-1]*q
for s,t,x in l:
    le = bisect.bisect_left(d,s-x)
    ri = bisect.bisect_left(d,t-x)
    while le < ri:
        if skip[le] == -1:
            ans[le] = x
            skip[le] = ri
            le += 1
        else:
            le = skip[le]

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

def main():
    from bisect import bisect_left as bl
    from itertools import accumulate as ac

    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    aa = [0]+list(ac(a))

    ok = 0
    ng = 10**15
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if sum([n-bl(a, mid-a[i]) for i in range(n)]) >= m:
            ok = mid
        else:
            ng = mid

    c = -m+sum([n-bl(a, ok-a[i]) for i in range(n)])
    ans = -c*ok
    for i in range(n):
        d = bl(a, ok-a[i])
        ans += aa[n]-aa[d]+(n-d)*a[i]
    print(ans)


main()

### FIXED CODE ###

def main():
    from bisect import bisect_left as bl
    from itertools import accumulate as ac

    n, m = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    aa = [0]+list(ac(a))
    an = aa[n]

    ok = 0
    ng = 10**10
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        q = 0
        for i in range(n):
            q += n-bl(a, mid-a[i])
        if q >= m:
            ok = mid
        else:
            ng = mid

    b = ok
    c = -m
    for i in range(n):
        c += n-bl(a, b-a[i])
    ans = -c*b
    for i in range(n):
        d = bl(a, b-a[i])
        ans += an-aa[d]+(n-d)*a[i]
    print(ans)


main()
### BUGGY CODE ###

a, b, c, k = map(int, input().split(' '))

cnt_a = 0
cnt_b = 0
cnt_c = 0

while k != 0:
    if a > 0:
        cnt_a += 1
        a -= 1
        k -= 1
    elif b > 0:
        cnt_b += 1
        b -= 1
        k -= 1
    else:
        cnt_c += 1
        c -= 1
        k -= 1

result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)


### FIXED CODE ###

a, b, c, k = map(int, input().split(' '))

cnt_a = 0
cnt_b = 0
cnt_c = 0

if (a > 0) & (a > k):
    cnt_a = k
    k = 0
else:
    cnt_a = a
    k = k - cnt_a

if (b > 0) & (b > k):
    cnt_b = k
    k = 0
else:
    cnt_b = b
    k = k - cnt_b

if c > 0:
    cnt_c = k

result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)
### BUGGY CODE ###

import sys
 
m = {}
def ev(v):
    if not v in m:
        m[v] = sum(range(1,v+1)) * 1.0/v
    return m[v]

N, K = [int(x) for x in sys.stdin.readline().strip().split(" ")]
p = [ev(int(x)) for x in sys.stdin.readline().strip().split(" ")]
 
m = 0
i = 0
while K+i <= N:
    v = 0
    for k in range(K):
        v += p[i+k]
    if m < v:
        m = v
    i += 1
print(m)


### FIXED CODE ###

import sys
 
ma = {}
def _sum(n):
    if not n in ma:
        ma[n] = sum(range(1,n+1))
    return ma[n]

def ev(v):
    return _sum(v) * 1.0/v
 
N, K = [int(x) for x in sys.stdin.readline().strip().split(" ")]
p = [ev(int(x)) for x in sys.stdin.readline().strip().split(" ")]
 

cur = sum([p[i] for i in range(K)])
_max = cur

i = K-1
j = 0

while i < N - 1:
    cur -= p[j]
    i += 1
    j += 1
    cur += p[i]
    if _max < cur:
        _max = cur

print(_max)
### BUGGY CODE ###

import sys
from collections import *
INF = 500000
mod = 10**9+7

H, W = map(int, input().split())
f = [input() for i in range(H)]
es = defaultdict(lambda : INF)
for i in range(H):
    for j in range(W-1):
        if f[i][j] == '.' and f[i][j+1] == '.':
            es[((i, j), (i, j+1))] = 1
            es[((i, j+1), (i, j))] = 1
for i in range(H-1):
    for j in range(W):
        if f[i][j] == '.' and f[i+1][j] == '.':
            es[((i, j), (i+1, j))] = 1
            es[((i+1, j), (i, j))] = 1
V = []
for i in range(H):
    for j in range(W):
        if f[i][j] == '.':
            es[((i, j), (i, j))] = 0
            V.append((i, j))
for k in V:
    for i in V:
        for j in V:
            tmp = es[(i, k)] + es[(k, j)]
            if tmp < es[(i, j)]:
                es[(i, j)] = tmp
ans = 0
for i in V:
    for j in V:
        if ans < es[(i, j)]:
            ans = es[(i, j)]
print(ans)


### FIXED CODE ###

import sys
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

def dijkstra(s):
    dist = defaultdict(lambda : INF)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u in es[v]:
            tmp = dv+1
            if tmp < dist[u]:
                dist[u] = tmp
                heappush(h, (tmp, u))
    return dist

H, W = map(int, input().split())
f = [input() for i in range(H)]
V = []
for i in range(H):
    for j in range(W):
        if f[i][j] == '.':
            V.append((i, j))
es = defaultdict(list)
for i in range(H):
    for j in range(W-1):
        if f[i][j] == '.' and f[i][j+1] == '.':
            es[(i, j)].append((i, j+1))
            es[(i, j+1)].append((i, j))
for i in range(H-1):
    for j in range(W):
        if f[i][j] == '.' and f[i+1][j] == '.':
            es[(i, j)].append((i+1, j))
            es[(i+1, j)].append((i, j))
ans = 0
for v in V:
    ans = max(ans, max(dijkstra(v).values()))
print(ans)
### BUGGY CODE ###

import itertools
N=int(input())
A=list(map(int,input().split()))
ans = 0
for i in itertools.combinations(A,2):
    ans += i[0]*i[1]
#print(ans)
print(ans%((10**9)+7))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
sumA = sum(A)
ans = 0
for i in range(N-1):
    x = A[i]
    sumA -= x
    ans += sumA*x
print(ans%((10**9)+7))
### BUGGY CODE ###

from functools import reduce
import sys
sys.setrecursionlimit(20000)

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

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

def lcm_numbers(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(N)]
mod = 10**9+7

ll = lcm_list(A)
ans = 0
for i in range(N):
    B[i] = (ll//A[i])%mod
    ans += B[i]
print(int(ans%mod))


### FIXED CODE ###

from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in range(1,n):
    l=lcm(l,a[i])
ans=0
for i in range(n):
    ans+=l//a[i]
    #ans%=mod
print(ans%mod)
### BUGGY CODE ###

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    gcd = xgcd(A[0],A[1])
    lcm = (A[0]*A[1]) // gcd
    for x in A[2:]:
        if max(lcm,x) % min(lcm,x) == 0:
            gcd = min(lcm,x)
        else:
            gcd = xgcd(lcm,x)
        lcm = (lcm * x) // gcd
    ans = 0
    b = [lcm // x for x in A]
    for x in b:
        ans = (ans + x) % 1000000007
    print(ans)

### FIXED CODE ###

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    g = gcd(A[0],A[1])
    lcm = (A[0]*A[1]) // g
    for x in A[2:]:
        lcm = (lcm * x) // gcd(lcm,x)
    print(sum((lcm//x) for x in A)%1000000007)