Problem:
 Score : 300 points    Problem Statement Given are N integers A_1,\ldots,A_N .  Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N , modulo (10^9+7) .      Constraints  2 \leq N \leq 2\times 10^5  0 \leq A_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  \ldots  A_N       Output Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j , modulo (10^9+7) .        Sample Input 1 3
1 2 3      Sample Output 1 11  We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11 .       Sample Input 2 4
141421356 17320508 22360679 244949      Sample Output 2 437235829

Solution (Python):
from functools import reduce

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

sums = [A_list[0]]

for i in range(1, N):
    sums.append(sums[i-1] + A_list[i])

result = 0
for i in range(1, N):
    result += sums[i-1] * A_list[i]

result %= 10**9 + 7

print(result)

Solution (Python):
import sys
input = sys.stdin.readline
BIG = 10**9 + 7

def sumpp(n,a):
    acc = 0
    tmp = 0
    sumv = sum(a)
    for i in range(n):
        tmp += a[i]
        acc += a[i] * (sumv - tmp)
    return acc % BIG

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(sumpp(n,a))

Solution (Python):
import numpy as np

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

mod = 1000000007
res = np.cumsum(A, dtype=np.float64)
ans = 0

for i in range(N-1):
    S = (int(res[N-1])-int(res[i])) % mod
    ans += A[i]*S
    ans %= mod

print(int(ans))

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    square = []
    for i in A:
        square.append(i**2)
    return (sum(A)**2 - sum(square))//2 % (10**9+7)


print(solve())

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
p = 0
s = sum(X)
for n in range(N):
  s -= X[n] 
  s = s % (10**9 + 7)
  p += s * X[n]
  p = p % (10**9 + 7)

print(p)

Solution (Python):
mod = 10**9+7 

def main():
  n = int(input())
  a = list(map(int, input().split()))
  wa = sum(a)%mod
  ans = 0
  for i in range(n):
    wa -= a[i]%mod
    ans += (a[i]*wa)
    ans %= mod
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
sum_sum = sum(a[1:])
for i in range(N):

  sum_n = (sum_n + (a[i] * sum_sum) % MOD) % MOD
  if i+1 < N:
  	sum_sum = sum_sum - a[i+1]
print(sum_n % MOD)

Solution (Python):
N = map(int, input())
An = list(map(int, input().split()))
mnum = 10 ** 9 + 7
CumSum = An[0]
answer = 0
for i in range(1, len(An)):
    answer = (answer + CumSum * An[i]) 
    CumSum = (CumSum + An[i])
print(answer%mnum)

Solution (Python):
N = map(int, input())
An = list(map(int, input().split()))
mnum = 10 ** 9 + 7
CumSum = An[0] % mnum
answer = 0
for i in range(1, len(An)):
    answer = (answer + CumSum * An[i]) % mnum
    CumSum = (CumSum + An[i]) % mnum
print(answer)

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

Solution (Python):
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

Dum = 0
Gum = 0

for i in range(0, N-1):
    Dum += A[i]
    Gum += Dum * A[i+1]

print(Gum % 1000000007)

Solution (Python):
mod = 10**9+7
n = int(input())
num = list(map(int,input().split()))
ans = 0
s = sum(num)

for i in num:
  s -= i
  ans += i*s
print(ans%mod)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


N = I()
A = LI()
mod = 10**9+7
s = sum(A)
s %= mod

a = s**2-sum(A[i]**2 for i in range(N))
a %= mod
a *= pow(2,mod-2,mod)
a %= mod

print(a)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

sum_A = sum(A)

ans = 0
for i in range(n-1):
    sum_A -= A[i]
    ans += A[i] * sum_A
ans %= 10**9+7
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

sum_A = sum(A)

ans = 0
for i in range(n-1):
    sum_A -= A[i]
    ans += A[i] * sum_A
ans %= 10**9+7
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i, a in enumerate(As, 1):
    ans += a*(SUM-a)
    ans %= mod
print(ans*pow(2, mod-2, mod)%mod)

Solution (Python):
import sys

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

mod = 10**9 + 7
ans = 0
sum_a = sum(A)
for i in range(N):
    sum_a -= A[i]
    ans += A[i] * sum_a
    ans %= mod

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
su = sum(a)
res = 0
for x in a:
    res += su*x
    res -= x*x
print(res//2%mod)

Solution (Python):
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
ans=0
for i in a:
  s-=i
  ans+=i*s
print(ans%mod)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
    x+=a[i]**2
y=sum(a)**2
print(((y-x)//2)%(10**9+7))

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

s = [0]*(N+1)
for i in range(N):
    s[i+1] = s[i] + A[i]
    
cnt = 0
for j in range(N):
    cnt =  (cnt + (A[j]*(s[N] - s[j+1])))%(10**9+7)
print(cnt)

Solution (Python):
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
A = list(map(int,input().split()))
a0 = ((sum(A)%p)*(sum(A)%p))%p
a1 = 0
for i in range(N):
    a1 = (a1+A[i]**2)%p
a = a0-a1
a = (pow(2,p-2)*a)%p
print(a)

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

mod=10**9+7

s=sum(a)%mod

ans=0
for i in range(n-1):
    s=(s-a[i])%mod
    ans=(ans + a[i]*s)%mod

print(ans)

Solution (Python):
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    ans = sum(A)
    ans *= ans
    ans -= sum([a * a for a in A])
    ans //= 2
    ans %= 1000000007
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
total = sum(alist)
sumlist = []
ans = 0
for i in range(len(alist)-1):
    total -= alist[i]
    ans += alist[i]*(total)
print(ans%mod)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N = I()
A = LI()
s = sum(A)
mod = 10**9+7
s %= mod

a = s**2-sum(A[i]**2 for i in range(N))
a %= mod
a *= pow(2,mod-2,mod)
a %= mod

print(a)

Solution (Python):
from itertools import accumulate


N = int(input())
A = list(map(int, input().split()))
MOD = 1_000_000_007
acc = list(accumulate(A, initial=0))

ans = 0
for i in range(N):
    ans += A[i] * (acc[N] - acc[i + 1])
    ans %= MOD
print(ans)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
total=sum(a)

mod=10**9+7

ans=0
for i in range(n-1):
  total-=a[i]
  ans+=a[i]*total
  ans%=mod

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=sum(a)**2
y=sum(a[i]**2 for i in range(n))
print(((x-y)//2)%1000000007)

Solution (Python):
N = int(input()); MOD = pow(10,9)+7
A = list(map(int,input().split()))
S = sum(A)**2%MOD
nijo = 0
for x in A:
  nijo = (nijo + x**2)%MOD
ans = (S-nijo)*pow(2,MOD-2,MOD)%MOD
print(ans%MOD)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)

MOD = 10**9+7
ans = 0
for i in range(N-1):
    ans += A[i] * (cums[-1] - cums[i+1])
    ans %= MOD
print(ans)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
ans = (sum(A)**2 - sum(a*a for a in A))//2
mod = 10**9 + 7

print(ans % mod)

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

length = len(a)
total = sum(a)

ans = 0
for i in range(0,length):
    total -= a[i]
    ans += (a[i] * total)


print(ans % (10**9 + 7))

Solution (Python):









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

s = 0
for i in range(N):
    s += seq[i]

s2 =0
for i in range(N):
    s2 += seq[i]**2


s0 = (s**2 -s2)//2

print(s0%(10**9+7))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
t=sum(a)
s=0
for i in range(n):
  s+=a[i]*a[i]

ans=(t*t-s)//2
ans=ans%(10**9+7)



print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7

S = sum(A)
ans = 0
for i in range(N):
    S = S - A[i]
    ans += A[i]*S

print(ans%MOD)

Solution (Python):
n= int(input())
mod=10**9+7
a= [int(x ) for x in input().split()]
b= a[:]

s=0
for i in range(n-2,-1,-1):
    b[i]=b[i+1]+b[i]
for i in range(n):
    s += (b[i]-a[i])*a[i]
print(s%mod)

Solution (Python):
n = int(input())
arr_a = list(map(int, input().split()))

mod = 10**9 + 7
memo = {}

for i in range(n):
    if i == 0:
        memo[n-i-1] = 0
    else:
        memo[n-i-1] = (memo[n-i] + arr_a[n-i]) % mod

ans = 0
for i in range(n):
    ans += arr_a[i] * memo[i]
    ans = ans % mod

print(ans)

Solution (Python):
n = int(input())
num_list = input().split()

mod_value = 10**9 + 7
sum_all = 0
sum_int = 0

for index in range(len(num_list) - 1):
  sum_int += int(num_list[index])
  sum_all += sum_int * int(num_list[index + 1])
  if sum_all > mod_value:
    sum_all %= mod_value

print(sum_all)

Solution (Python):
def main():
    n=int(input())
    a=list(map(int, input().split()))
    mod=10**9+7
    ans=((sum(a)%mod)**2)%mod
    for i in range(n):
      ans-=a[i]**2
      ans%=mod
    m=pow(2,mod-2,mod)
    print(ans*m%mod)   
main()

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))

Solution (Python):
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(1, n+1):  a[i] += a[i-1]
ans, m = 0, int(1e9+7)
for i in range(1, n):
    ans = (ans + (a[i]-a[i-1])*(a[n]-a[i])) % m

print(ans)

Solution (Python):
n = input()
arr = list(map(int, input().split()))

MOD = 10**9 + 7

res = 0
total = sum(arr)



for a in arr:
    total -= a
    res += total * a % MOD
    


print(res % MOD)

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

sum_a = sum(a)

ans = 0

for i in range(n - 1):
    sum_a -= a[i]
    ans += a[i] * sum_a

ans = ans % (10 ** 9 + 7)

print(ans)

Solution (Python):
n = int(input())

a_list = list(map(int, input().split()))
sum_l = sum(a_list)
ans = 0
for i in range(n-1):
    sum_l -= a_list[i]
    ans += sum_l * a_list[i]
print(ans % 1000000007)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
 
sum_l=sum(l)
ans=0
mod=10**9+7
 
for i in range(n):
  sum_l-=l[i]
  ans+=l[i]*sum_l
  
print(ans%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split(" ")))
mod = 10 ** 9 + 7
s = 0
for i in range(n):
    s = (s + a[i])
s = (s * s)
for i in range(n):
    s = (s - (a[i] ** 2) )
s = (s // 2) %mod
print(s)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))

sum_l=sum(l)
ans=0
mod=10**9+7

for i in range(n):
  sum_l-=l[i]
  ans+=l[i]*sum_l
  
print(ans%mod)

Solution (Python):
N=int(input())
B=[int(a) for a in input().split()]

sum=0
ans=0
for i in range(len(B)-1):
    sum+=B[i]
    ans+=sum*B[i+1]
print(ans%1000000007)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
res = 0
mod = 10**9 + 7
for i in range(N-1):
	s -= A[i]
	res += s*A[i]
print(res%mod)

Solution (Python):
n = int(input())
a = [int(s) for s in input().split()]
s=sum(a)

total=0

for i in range(n-1):
  s=s-a[i]
  total=total+a[i]*s%1000000007
  
print(total%1000000007)

Solution (Python):
MOD = 1000000007
n = int(input())
nums = list(map(int, input().split()))
x = sum(nums)
y = sum([(nums[i]**2) for i in range(n)])
print(((x**2 - y)//2)% MOD)

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
 

def cumsum(xs):
    pass

def main():
    n = int(input())
    alist = list(map(int, input().split()))
    max_num = 10**9 + 7
    ans = 0
    sum_num = sum(alist)

    for i in range(n-1):
        sum_num -= alist[i]
        ans += alist[i] * sum_num
        

    print(ans%max_num)

if __name__ == "__main__":
    main()

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

ans = 0
u = 0
mod = 10**9+7
for i in range(N) :
    ans += A[i] * u % mod
    u += A[i] % mod
print(ans % mod)

Solution (Python):
N=int(input())

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

mod=10**9+7
summy=[]
a=0
for i in range(N):
    a += A[i]
    a %= mod
    summy.append(a)

ans=0
for i in range(N-1):
    ans += summy[N-2-i]*A[N-1-i]
    ans %= mod
print(ans)

Solution (Python):
MOD = 10**9+7

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

S = sum(A) % MOD
ans = 0

for i in A:
    S -= i
    ans += S*i
    ans %= MOD

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ruiseki = 0
count = 0
for i in range(n-1):
    ruiseki += a[i]
    count += ruiseki * a[i+1]
mod = 10**9 + 7
if count >= mod:
    print(count%mod)
else:
    print(count)

Solution (Python):
n = int(input())
li_a = list(map(int, input().split()))
answer = 0
su = sum(li_a)
mo = (10 ** 9) + 7
for idx, a in enumerate(li_a):
    su = su - a
    answer += (a * su)
print(answer % mo)

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

mod = 10**9 + 7
ans = 0

b = [a[0]]
for i in range(n-1):
    b.append((b[-1] + a[i+1]) % mod)

for i in range(n-1):
    ans += a[i] * (b[-1] - b[i])
    ans %= mod

print(ans)

Solution (Python):
N = int(input()); MOD = pow(10,9)+7
A = list(map(int,input().split()))
S = sum(A)**2%MOD
nijo = 0
for x in A:
  nijo = (nijo + x**2)%MOD
ans = (S-nijo)*pow(2,MOD-2,MOD)%MOD
print(ans%MOD)

Solution (Python):
MOD = 10**9+7

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

S = sum(A) % MOD
ans = 0

for x in A:
  S -= x
  S % MOD
  ans += S * x
  ans %= MOD
  
print(ans)

Solution (Python):

def input_one_number():
    return int(input())


def input_multiple_number():
    return map(int, input().split())


def input_multiple_number_as_list():
    return list(map(int, input().split()))

n = input_one_number()
a = input_multiple_number_as_list()

mod = 10**9+7
ssum = 0

sumA = sum(a)

for _a in a:
	ssum += _a * (sumA-_a)

print(ssum//2%mod)

Solution (Python):
N = int(input())
num = [int(i) for i in input().split()]

sum = [0]
sum1 = 0
for i in range(N):
    sum.append(num[i] + sum[i])

for x in range(N):
    if((num[x] * sum[x])//(10**9 + 7)>= 1 ):
        sum1 += num[x]*sum[x] - ((num[x] * sum[x])//(10**9 + 7))*(10**9 + 7)
    else:
        sum1 += num[x]*sum[x]

print(sum1 - (sum1//(10**9 + 7))*(10**9 + 7) )

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
ans = 0
Q = int(1e9 + 7)
 
sumA = sum(A)
 
for i in range(N-1):
    sumA -= A[i]
    ans += sumA * A[i]
    ans %= Q
 
print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
S = 0
P = 10**9 + 7
for i in range(N):
  S = (S + A[i])%P
ans = 0
for i in range(N):
  S = (S-A[i]+P)%P
  a = (A[i]*S)%P
  ans = (ans + a)%P
print(ans)

Solution (Python):
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())
a_list = list(map(int, input().split()))
a_list = np.array(a_list)

a = a_list.sum() % MOD
b = ( (a_list**2)%MOD ).sum() % MOD
c = ( a**2 - b) % MOD

if c&1:
    c += MOD

print(c//2)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))

s_2 = 0
for i in a_list:
    s_2 += i**2

ans = (sum(a_list)**2 - s_2)//2  

ans = ans%(10**9+7)
print(ans)

Solution (Python):
N = int(input())
Al = input().split()
A = list( map((lambda x: int(x)), Al))
num = 0
ma = 10**9 + 7
li = 0

for i in range(N-1, 0, -1):
  li += A[i]
  num += A[i-1] * li

num = num % ma
print(num)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
c=sum(a)
for i in range(n):
    c=c-a[i]
    b=(a[i]*c)
    ans=ans+b
d=ans%(1000000007)
print(d)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
ans = 0
 
for i in range(N):
  sum_A = (sum_A - A[i])%(10**9 + 7)
  ans += A[i] * sum_A
  
print(ans%(10**9 + 7))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
ans = 0

for i in range(N):
  sum_A = sum_A - A[i]
  
  ans += A[i] * sum_A
  
print(ans%(10**9 + 7))

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
sum_a = [0] * len(aaa)
sum_a[0] = aaa[0]
for i in range(n - 1):
    sum_a[i + 1] = sum_a[i] + aaa[i + 1]

for i in range(n):
    ans += aaa[i] * (sum_a[n -1] - sum_a[i])

print(ans%mod)

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

_INPUT = """\
4
141421356 17320508 22360679 244949
"""

def main(*, input=input):
    sr = lambda: input()
    ir = lambda: int(sr())
    lr = lambda: list(map(int, sr().split()))

    n = ir()
    a = lr()
    a1 = [0]
    for num in a:
        a1.append(a1[-1]+num)
    ans = 0
    for i,num in enumerate(a):
        tmp = (a1[n]-a1[i+1])%mod
        tmp = (tmp*num)%mod
        ans = (ans+tmp)%mod
    print(ans)

if __name__ == "__main__":
    import io, sys

    

    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
MOD= 10**9 + 7
toki = [0]*(n+1)
shigi=0

toki[0] = sum(a)-a[0]
for i in range(1, n-1):
  toki[i] = toki[i-1]-a[i]
  
for i in range(n-1):
  shigi += (a[i] * toki[i])

print(shigi%MOD)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
x, y = 0, 0
mod = 10**9+7
for a in A:
    x = (x + a) % mod
    y = (y + a * a) % mod
print((x * x % mod - y) * pow(2, mod - 2, mod) % mod)

Solution (Python):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
ans=0
for i in range(N-1):
  S-=A[i]
  ans+=(A[i]*S)%MOD
print(ans%MOD)

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
mod = 10**9+7


cumsum = [0]*(n+1)
for i in range(n):
    cumsum[i+1] = lst[i] + cumsum[i]


ans = 0
for i in range(n-1):
    ans += (cumsum[n] - cumsum[i+1]) * lst[i]
print(ans % mod)

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
mod = 10**9+7


sums = [0]*(n+1)
for i in range(n):
    sums[i+1] = lst[i] + sums[i]


ans = 0
for i in range(n-1):
    ans += (sums[n] - sums[i+1]) * lst[i]
print(ans % mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s, mod = sum(a)-a[0], 1000000007
ans = a[0]*s
for i in range(1, n):
    s -= a[i]
    ans = (ans % mod + ((s % mod) * a[i]) % mod) % mod

print(ans % mod)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
cum_A = [0] * N
cum_A[0] = A[0]
for i in range(1, N):
    cum_A[i] = cum_A[i - 1] + A[i]

ans = 0
for i in range(N - 1):
    inner_sum = cum_A[-1] - cum_A[i]
    ans += A[i] * inner_sum

print(ans % (10**9 + 7))

Solution (Python):


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

Solution (Python):
import itertools


n=int(input())
A=list(map(int,input().split()))
Ar=list(itertools.accumulate(A))
ans=0
for i in range(n-1):
    ans+=A[i]*(Ar[n-1]-Ar[i])
    ans%=10**9+7
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = map(int, input().split())
S = 0
S2 = 0
M = 10**9+7
for a in A:
  S += a
  S %= M
  S2 += a*a
  S2 %= M


ans = (S * S - S2) * pow(2, -1, M)
ans %= M
print(ans)

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

mod = 10 ** 9 + 7
sum = sum(A) **  2

squ = 0
for i in range(N):
    squ +=  A[i] ** 2

answer = int(((sum - squ)  //  2 ) % mod)
print(answer)

Solution (Python):

mod = 10 ** 9 + 7


N = int(input().rstrip())
As = list(map(int, input().rstrip().split()))
ans = 0
add = 0

for i in range(N):
	add += As[i]
	add %= mod
ans = add * add % mod

for i in range(N):
	ans -= As[i] * As[i] % mod
	if (ans < 0):
		ans += mod

ans *= int((mod + 1) / 2)
ans %= mod

print(ans)

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

A_sum = sum(A)
A_squaresum = sum([a ** 2 for a in A])
answer = ((A_sum ** 2 - A_squaresum) // 2) % (10 ** 9 + 7)

print(answer)

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

x = sum(A)
y = sum([A[i] ** 2 for i in range(N)])

print(((x ** 2 - y) // 2) % (10 ** 9 + 7))

Solution (Python):
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) // 2
    print(int(ans % mod))


if __name__ == '__main__':
    main()

Solution (Python):

import numpy as np

N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
A = np.array(A)
csA = np.zeros((N+1), np.int64)
for i in range(N):
    csA[i+1] = (csA[i] + A[i]) % MOD
    
ans = 0
for i in range(N-1):
    ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD)

Solution (Python):
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()
b = 0
ans = 0

for i in a:
    b += i ** 2


ans = ((sum(a) ** 2 - b) // 2) % (10 ** 9 + 7)
print(ans)

Solution (Python):


N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7

csA = [0] * (N+1)
for i in range(N):
    csA[i+1] = csA[i] + A[i]

ans = 0
for i in range(N-1):
    ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD)

Solution (Python):
N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
S = sum(A)

ans = 0
for i in range(N-1):
    S -= A[i]
    ans += (A[i] * S) % MOD
print(ans%MOD)

Solution (Python):

_INPUT = """\
4
141421356 17320508 22360679 244949
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
def main():
    n = int(input())
    a = list(map(int, input().split()))
    cumsum = list(itertools.accumulate(a))

    sum1 = 0
    for i in range(len(a)):
        mult = a[i] * (cumsum[n-1] - cumsum[i])
        sum1 += mult

    print((sum1 % (10**9 + 7)))


if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools
    from collections import deque

    
    main()

Solution (Python):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
ans=0
for i in range(N-1):
  S-=A[i]
  ans+=(A[i]*S)%MOD
print(ans%MOD)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
S = []
e = 0
for i in A:
    e += i
    S.append(e)
    
ans = 0
for i in range(N-1):
    ans += A[i]%(10**9+7)*((S[N-1] - S[i])%(10**9+7))
    
print(ans%(10**9+7))

Solution (Python):
from itertools import accumulate
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    MOD = 10**9+7

    accm = list(accumulate(A))

    ans = 0
    for i in range(N-1,0,-1):
        ans += A[i] * accm[i-1] % MOD
        ans %= MOD

    print(ans%MOD)
        

if __name__ == '__main__':
    solve()

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

mod=10**9+7

B=[0]
for i in range(1,N+1):
    B.append(A[i-1]+B[i-1])

ans=0
for i in range(N-1):
    ans+=A[i]*(B[N]-B[i+1])
    ans%=mod

print(int(ans))

Solution (Python):
mod = 1000000007
n = int(input())
a = list(map(int, input().split()))
ans = 0
a_sum = sum(a) 
a_total = a_sum*a_sum
lat = 0
for i in a:
    lat = lat + i*i
ans = (a_total - lat) // 2
ans = ans%mod
print(ans)

Solution (Python):
N = int(input())
al = list(map(int,input().split()))
sss=0
pss=0
for i in range(1,N):
    pss+=al[i-1]
    sss+=al[i]*pss
print(sss%1000000007)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))

sum = 0
for i in range(N):
    sum += As[i]
    sum %= 10**9+7

ans = 0
for i in range(N):
    sum -= As[i]
    ans += As[i]*sum
    ans %= 10**9+7

print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    ans = (sum(A) ** 2 - sum([i ** 2 for i in A])) // 2 % MOD
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()

n_sum = a[0]
sum = 0
for i in range(1,n):
  sum += a[i] * n_sum
  n_sum += a[i]
print(sum % (10**9 + 7))

Solution (Python):
N=int(input())
List = list(map(int, input().split()))
S=0
for i in range(len(List)):
    S+=List[i]
mod=10**9+7
S=S%mod
T=0
s=0
for i in range(len(List)):
    s+=List[i]
    s=s%mod
    T+=List[i]*(S-s)
    T=T%mod
print(T)

Solution (Python):
import itertools

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

A.sort()
ac = list(itertools.accumulate(A))

ans = 0
for i in range(N):
    ans += A[i]*(ac[-1]-ac[i])
print(ans % MOD)

Solution (Python):
def execute(N, A):
    dst = 0
    s = sum(A)
    for v in A:
        s -= v
        dst += v * s

    return dst % (10**9+7)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    print(execute(N, A))

Solution (Python):
N = int(input())

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

ans = 0
sum = 0

for i in range(N):
    sum += a[i]

for i in range(N-1):
    sum -= a[i]
    ans += a[i]*sum

m = 10**9 + 7

ans = ans % m

print(ans)

Solution (Python):
N=int(input())
Alist=list(map(int,input().split()))
sum1=0
sum2=0
for i in range(N):
  sum1=sum1+Alist[i]
  sum2=sum2+(Alist[i])**2
ans=(sum1**2-sum2)//2
print(ans%(10**9+7))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
sum = 0
ans = 0

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

for i in range(n-1):
    sum -= a[i]
    ans += a[i] * sum

print(ans % (10**9 + 7))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    mod = 10**9 + 7
    sum_A = sum(A)%mod
    ans = 0
    for a in A:
        sum_A -= a
        ans += a*sum_A%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    mod = 10**9 + 7
    sum_A = sum(A)%mod
    ans = 0
    for a in A:
        sum_A -= a
        ans += a*sum_A%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Solution (Python):
N = int(input())
p = 10**9 + 7
A = [int(i) for i in input().split()]
S = sum(A)%p
ans = S**2 % p
B = [(i**2%p) for i in A]
ans -= sum(B)%p
if ans < 0:
    ans += p
if ans % 2 == 0:
    print(ans//2)
else:
    print((ans+p)//2)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
S = [0] * (N+1)      
s = 0
CONST = 10**9+7


for i in range(N):
    S[i+1] = S[i] + A[i]


for i in range(N-1):
    s += A[i] * ((S[N] - S[i+1]) % CONST)
    s %= CONST

print(s)

Solution (Python):

def input_array():
	return list(map(int,input().split()))
  
n=int(input())
A=input_array()
acc_A=[0]

for i in range(n):
	acc_A.append(acc_A[i]+A[i])
ans=0
for i in range(n):
	ans+=A[i]*(acc_A[n]-acc_A[i+1])

print(ans %(10**9+7))

Solution (Python):
N = int(input())

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

MOD = 10 ** 9 + 7

x = 0
ans = 0
for i in range(len(A)):
    ans += A[i] * x % MOD
    x += A[i] % MOD
print(ans%MOD)

Solution (Python):
N = int(input())

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

MOD = 10 ** 9 + 7

x = 0
ans = 0
for i in range(len(A)):
    ans += A[i] * x
    x += A[i]
print(ans%MOD)