peterverebics/CodeNet_Python_118 huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline

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

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


main()
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
aa = [a[0] % mod]
for i in range(1, n-1):
    aa.append((aa[i-1] + a[i]) % mod)
ans = 0
for i in range(n-1):
    ans += ((aa[i] * a[i+1]) % mod)
print(ans % mod)
N = int(input())
A = list(map(int,input().split()))

MOD = 10**9 + 7

S1, S2 = 0, 0
for a in A:
    S1 += a
    S2 += a * a % MOD
    S1 %= MOD
    S2 %= MOD

print(((S1*S1%MOD-S2+MOD) % MOD) * pow(2,MOD-2,MOD) % MOD)
n=int(input())
l=list(map(int,input().split()))
an=0;md=10**9+7
suf=[0]*n
suf[-1]=l[-1]
for i in range(n-2,-1,-1):
  suf[i]=suf[i+1]+l[i]
for i in range(n-1):
  an=(an+l[i]*suf[i+1])%md
print(an)
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)
n = int(input())
A = list(map(int, input().split()))
M = 10 ** 9 + 7
ans = 0
B = [A[0]]
for j in range(1,n):
    B.append(A[j]+B[j-1])
for i in range(n-1):
    ans += A[i] * (B[-1]-B[i])
    ans %= M
ans %= M
print(ans)
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7

s = sum(a)
ans = 0

for i in a:
  s -= i
  s %= mod
  ans += s*i
  ans %= mod
  
print(ans)
import sys
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = A[::-1]
    B = list(itertools.accumulate(A))
    MOD = 10**9+7
    ans = 0
    for i in range(N - 2, -1, -1):
        ans = (ans + A[i + 1] * B[i]) % MOD
    print(ans)


if __name__ == '__main__':
    main()
n = int(input())
a = list(map(int, input().split()))

sum = sum(a) - a[0]

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

MOD=7+10**9
SUM=sum(A)
ans=0

for i in range(N-1):
    SUM-=A[i]
    ans += A[i]*SUM %MOD
print(ans %MOD)
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)  # 累積和テーブル B[i] = sum(A[:i])
mod = 10**9 + 7
ans = 0

for i in range(N):
    B[i+1] = B[i] + A[i]  # 累積和

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

print(int(ans))
m = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7
ans = 0

tmp_sum = sum(a[1:m]) % mod

for x in range(m-1):
  if a[x] % mod != 0:
    ans += (a[x] * tmp_sum) % mod
  
  tmp_sum -= a[x+1] % mod

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

mod = 10**9+7

count = 0

num = sum(A) % mod

ans = 0
for a in A[:-1]:
    num = num-a
    ans = (ans+a*num) % mod

print(ans)
import sys
input = sys.stdin.readline
 
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
 
sum_A = sum(A) % mod
ans = 0
for a in A[:-1]:
  sum_A -= a
  sum_A %= mod
  ans += a * sum_A
  ans %= mod

ans %= mod
print(ans)
N = int(input())
A = list(map(int, input().split()))

MOD  = 10**9 + 7

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

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

summ = 0
ans = 0
for i in range(1, n):
    summ += a[-i]
    ans += a[-(i + 1)] * summ
    ans %= MOD

print(ans % MOD)
N=int(input())
l=list(map(int,input().split()))
b=10**9+7
d=(sum(l))**2
c=0
for i in range(N):
  c=c+l[i]**2
print((d-c)//2%b)
N = int(input())

data = input().split()

data = [int(s) for s in data]

num = 0
ans = 0
sum = sum(data)

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

print(ans % 1000000007)
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
sumA = 0
for ai in A:
    sumA = (sumA + ai) % MOD
ans = 0
for ai in A:
    sumA = sumA - ai
    ans = (ans + sumA * ai) % MOD

print(ans)
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

all_item = sum(a)

ans = 0
for i in range(n):
    all_item = (all_item - a[i])%mod
    ans = (ans + all_item*a[i])%mod
print(ans)
n = int(input())
a_list = list(map(int,input().split()))
sum_a = sum(a_list)

sum = 0
for i in range(n):
  sum += a_list[i] * (sum_a-a_list[i])
  sum = sum%(10**9+7)
  sum_a -= a_list[i]
print(sum)
from itertools import accumulate
n=int(input())
A=[int(i) for i in input().split()]

B=list(accumulate(A))

s = 0 
for i in range(n):
    s += A[i]*(B[-1]-B[i])
    s %= (10**9+7)
print(s)
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)
n=int(input())
a=list(map(int,input().split()))
sum=0
mod=10**9+7
for i in range(n):
    sum+=a[i]
sum=sum**2
for i in range(n):
    sum-=a[i]**2
sum=(sum//2)%mod
print(sum)
N=int(input())
List = list(map(int, input().split()))
midList = [0]*(N-1)
mid = 0
for i in range(N-2,-1,-1):
  mid += List[i+1]
  midList[i] = mid
res=0
for i in range(N-1):
  a = List[i] % 1000000007
  b =  midList[i] % 1000000007
  res += a*b
print(res%1000000007)
n = int(input())
a = list(map(int, input().split()))

bs = 10**9 + 7
s = sum(a)
sm = 0

for i, ai in enumerate(a):
    s -= ai
    sm += (ai * s) % bs
    sm = sm % bs

print(sm)
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
l=[]
for i in range(len(a)-1):
  b-=a[i]
  l.append(a[i]*b)
print(sum(l)%(1000000007))
import math

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

for i in range(N-1):
    tmp+=A[i]
    ans+=tmp*A[i+1]
print(ans%((10**9)+7))
from itertools import accumulate

mod = 10 ** 9 + 7
input()
l = list(map(int, input().split()))
print(sum(a * b % mod for a, b in zip(list(accumulate(l))[:-1], l[1:])) % mod)
N = int(input())
b = 10**9+7
A = list((int(x) for x in input().split()))
sum = 0
for a in A:
  sum += a
ans = 0
for i in range(N-1):
  sum -= A[i]
  ans += A[i]*sum
print(ans % b)
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ac = list(accumulate(a))

ans = 0
for i in range(n-1):
    ans += (ac[i]*a[i+1])
    ans %= MOD
print(ans)
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A = list(mi())

    s = 0
    t = 0
    for i in range(N):
        s += A[i]*A[i]
        t += A[i]

    print(((t*t-s)//2)%MOD)

if __name__ == '__main__':
    main()
n=int(input())
a=[int(x) for x in input().split()]
m=10**9+7
s=sum(a)
ans=0
for i in range(n-1):
  s-=a[i]
  ans+=a[i]*s
  ans%=m
ans%=m
print(ans)
N = int(input())

ai_char = map(str, input().split(" "))
Ai = []
for i in ai_char:
    Ai.append(int(i))

mod_val = 1000000007
N1 = N-1
sum = 0

sum_tmp = 0
for j in range(0, N):
    sum_tmp += Ai[j]

for i in range(N1):
    sum_tmp -= Ai[i]
    sum += Ai[i] * sum_tmp

    if sum > mod_val:
        sum = sum % mod_val


print(int(sum))
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)
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
AA = 0
for i in range(N):
    AA += A[i]**2
    AA %= mod
print((sum(A)**2-AA)*pow(2,mod-2,mod) % mod)
mod = 10 ** 9 + 7
n = int(input())
a_list = list(map(int, input().split()))
result = 0
a_sum = sum(a_list)
for i in a_list:
    a_sum -= i
    result += i * a_sum
print(result % mod)
MOD = 1000000007
n, *a = map(int, open(0).read().split())
wa = a + [0]
for i in range(n-1, 0, -1):
    wa[i-1] += wa[i]

ans = 0
for i in range(n):
    ans += a[i] * wa[i+1]
    ans %= MOD
print(ans)
n = int(input())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

res = 0
tmp = 0
for i in range(1, n):
    tmp += A[i - 1]
    res += A[i] * tmp
    res %= MOD

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

sA = sum(As) % (10 ** 9 + 7)
print((sA * sA - sum( (A * A % (10 ** 9 + 7) for A in As) ) ) * pow(2, -1, 10 ** 9 + 7) % (10 ** 9 + 7))
n = int(input())
v = [int(x) for x in input().split()]
suma, ans = sum(v), 0
for i in range(n - 1):
    suma -= v[i];
    ans += (suma * v[i])
print(ans % 1000000007)
n=int(input())
z=[int(x) for x in input().split(' ')]
s=sum(z)
md=1000000007
ans=0
for i in range(n):
    s-=z[i]
    ans+=s*z[i]
print(ans%md)
n= int(input())
a= [int(i) for i in input().split()]
pref=[0]*n
m = 10**9+7
pref[0] = a[0]%m
for i in range(1,n):
    pref[i] =  (pref[i-1]+a[i])%m
m = 10**9+7
ans = 0
#print(pref)
for i in range(n-1):
    ans+= (a[i]%m *((pref[n-1]-pref[i])%m))%m
    ans = ans%m
print(ans)
n = int(input())
a = list(map(int, input().split()))

ans = 0
mod = 10 ** 9 + 7
a_r = list(reversed(a))
sumlist = [a_r[0]]
for i in range(1,len(a)):
  sumlist.append(sumlist[-1] + a_r[i])
sumlist.reverse()
sumlist = sumlist[1:]

for i in range(len(sumlist)):
  ans += a[i] * sumlist[i]

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

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

print(ans)
n = int(input())
a = list(map(int,input().split()))
 
mod = 10**9+7
sum_a = sum(a)%mod
sum_a2 = sum_a**2%mod
 
for i in range(n):
    sum_a2 -= (a[i]**2)%mod
    sum_a2 %= mod
    
if sum_a2%2 == 0:
    ans = sum_a2//2
else:
    ans = ((sum_a2+mod)//2)%mod

print(ans)
n,*l=map(int,open(0).read().split())
print((sum(l)**2-sum(i**2 for i in l))//2%(10**9+7))
n = int(input())
a = list(map(int,input().split()))

MOD=10**9+7

sum1=0
for i in range(n):
    sum1+=a[i]
    sum1%=MOD

sum1*=sum1
sum1%=MOD
sum2=0
for i in range(n):
    sum2+=pow(a[i],2,MOD)
    sum2%=MOD

t = sum1-sum2
if t<0:
    t+=MOD

print((t)*pow(2,MOD-2,MOD)%MOD)
N = int(input())
A = list(map(int, input().split()))

ans = 0
mod = 10 ** 9 + 7
num = sum(A)

for a in A:
    num -= a
    ans += a * num

print(ans % mod)
from sys import stdin
input = stdin.readline

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

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

ans = ans % MOD

print(ans)
def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))

    # 面積として見る: 縦*横
    square = sum(A) ** 2

    # 対角線
    diag = sum([a * a for a in A])

    ans = (square - diag) // 2
    print(ans % MOD)


if __name__ == "__main__":
    resolve()
n=input()
lst=list(map(int,input().split()))
m=sum(lst)%(10**9+7)
s=0
for i in lst:
    s=(s+i*i)%(10**9+7)
a=(m*m-s)%(10**9+7)
if a%2:print(a//2+5*10**8+4)
else:print(a//2)
n = int(input())
a = list(map(int,input().split()))

ans = 0
s = sum(a)
for i in range(n):
    ans += (s-a[i]) * a[i]
print((ans//2)%1000000007)
n=int(input())
A=list(map(int,input().split()))
s=0
m=10**9+7
for i in A:
    s+=i
    s%=m
ans=0
for i in range(n-1):
    s-=A[i]
    if s<0:
        s+=m
    ans+=(A[i]%m)*s
    ans%=m
print(int(ans))
mod = 1000000007
n = int(input())
a = list(map(int,input().split()))
ans = 0
b = sum(a)
for i in range(n-1):
    b = b-a[i]
    ans += (a[i]*(b))%mod
print(ans%mod)
n = int(input())
a = list(map(int,input().split()))
b = sum(a)
m = 10**9 + 7
ans = 0
for i in range(n):
    b -= a[i]
    ans += a[i]*b % m
    ans %= m
print(ans)
l = int(input())
num = input().split(' ')
num = [int(i) for i in num]
ans = 0
s = sum(num)
for i in range(l):
    s -= num[i]
    ans += num[i] * s
print(ans%(10**9+7))
N = int(input())
A = list(map(int, input().split()))

MOD = 10**9 + 7
sum_A = 0
for i in range(N):
    sum_A = (sum_A + A[i]) % MOD

sum = 0
for i in range(N):
    sum_A = (sum_A - A[i]) % MOD
    sum = (sum + sum_A*A[i]) % MOD 


print(sum)
n = int(input())
a = list(map(int, input().split()))
s = [0] * n

for i in range(1, n):
    s[i] = s[i-1] + a[i-1]

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

mod = 10**9 + 7

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

print(ans%mod)
n=int(input())
a=list(map(int,input().split()))
a.reverse()
l=[0]*n
l[0]=a[0]
for i in range(n-1):
  l[i+1]=l[i]+a[i+1]
ans=0
mod=10**9+7
for j in range(1,n):
  ans+=(a[j]*l[j-1])%mod
print(ans%mod)
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import itertools
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=list(map(int,pin().split()))
  mod=10**9+7
  B=list(itertools.accumulate(A))
  ans=0
  for i in range(N-1):
    ans+=A[i]*(B[N-1]-B[i])
  print(ans%mod)
  return 
main()
n = int(input())
a = list(map(int, input().split()))
ans = 0
a_sum = sum(a)
a_sum -= a[0]
for i in range(n - 1):
    ans += a[i] * a_sum
    a_sum -= a[i + 1]
ans %= 1000000007
print(ans)
N,*A = map(int, open(0).read().split())
Asq=[a**2 for a in A]
S = (sum(A)**2-sum(Asq))//2
print(S%(10**9+7))
a=input()
b=input().split()
N=int(a)
c=[]
ans=0
for i in range(N):
    c.append(int(b[i]))
s=sum(c)
for i in range(N):
    s=s-c[i]
    ans+=c[i]*s
print(ans%1000000007)
n=int(input())
a=list(map(int,input().split()))
ans=0
cum=[0]
for i in range(n):
    cum.append((cum[i]+a[i])%(10**9+7))
for i in range(n):
    # print(a[i],cum[-1]-cum[i+1])
    ans+=a[i]*(cum[-1]-cum[i+1])%(10**9+7)
    ans%=(10**9+7)
print(ans)
N = int(input())
input = [int(s) for s in input().split()]
ans = 0
temp=sum(input)
for i in range(N-1):
    temp=temp-input[i]
    ans = (ans + (input[i]*((temp)%(10**9+7)))%(10**9+7))%(10**9+7)
print(ans)
import sys

MOD = 10 ** 9 + 7


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = sum(a) ** 2
    for e in a:
        ans -= e ** 2
    ans //= 2
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()
MODINT = 1000000007
n = int(input())
A = list(map(int,input().split()))
prodsum = [0]*n
prodsum[0] = A[0]
for i in range(1,n):
    prodsum[i] = prodsum[i-1]+A[i]
# print(prodsum)
ans = 0
for i in range(n-1):
    ans += A[i]*(prodsum[-1]-prodsum[i])
print(ans%MODINT)
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
  x+=a[i]
x=x**2
y=0
for j in range(n):
  y+=a[j]**2
z=(x-y)//2
print(z%(10**9+7))
#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

    sum_A = sum(A) % mod
    ans = 0
    for a in A:
        sum_A -= a
        if sum_A < 0:
            sum_A += mod
        ans += a * sum_A
        ans %= mod
    print(ans % mod)


if __name__ == '__main__':
    main()
from itertools import accumulate

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

mod = 10 ** 9 + 7

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

print(ans)
N = int(input())
A = list(map(int,input().split()))
s =0
M = 10**9 +7
As = sum(A)
for i in range(N-1):
  As = As - A[i]
  s += (A[i] * As)%M
print(s%M)
n=int(input())
x = list(map(int, input().split()))
total=0
t=sum(x)  
for i in range(n):
 
  t=t-x[i]
  total=total+x[i]*(t)
   
print(total %1000000007)
N = int(input())
A = list(map(int, input().split()))

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

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

for i in range(n-1):
  num+=a[i]
  ans+=a[i+1]*num
  
print(ans%1000000007)
N=int(input())
A=list(map(int,input().split()))

modular=10**9+7
sum=0

AllSum=0
for i in range(N):
  AllSum+=A[i]
  AllSum=AllSum%modular

  
RuisekiWa=[]
NextSum=AllSum

for i in range(N):
  RuisekiWa.append((NextSum-A[i])%modular)
  NextSum=RuisekiWa[i]

#print(RuisekiWa)
for i in range(N):
  sum+=(A[i]*RuisekiWa[i])%modular
  sum=(sum%modular)
    
print(sum%modular)
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()
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from  itertools import accumulate

def get_int():return int(stdin.readline().strip())
def get_tuple():return map(int, stdin.readline().split())
def get_list():return list(map(int, stdin.readline().split()))

n = get_int()
ls = get_list()
mod = 10**9+7
pref_sum = list(accumulate(ls))

ans = 0
for i in range(1,n):
    ans = (ans+ls[i]*(pref_sum[i]-ls[i]))%mod
print(ans)
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)
n=int(input())
vec=list(map(int,input().split()))
mod=10**9+7
wa=[i for i in vec]
for i in range(n-1):
  wa[i+1]+=wa[i]
ans=0
for i in range(n):
  ans += vec[i]*((wa[n-1]-wa[i])%mod)%mod
  ans %= mod
print(ans)
n = int(input())
a = list(map(int,input().split()))

p = 10 ** 9 + 7

suma = 0
dsum = 0
for i in a:
  suma = (suma + i) % p
  dsum = (dsum + i ** 2) % p

sa2 = (suma ** 2) % p
ans2 = (sa2 - dsum) % p
if ans2 % 2  == 0:
  ans = ans2 // 2
else:
  ans = (ans2+p) // 2
print(ans)
#template
def inputlist(): return [int(j) for j in input().split()]
#template

mod = 10**9 + 7
N = int(input())
A = inputlist()

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

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

s = sum(A) % mod
s += mod
ss = 0
for i in range(N):
    ss += A[i]**2 % mod

ss = ss % mod
if (s**2 - ss) % 2 == 1:
    ss -= mod

print((((s**2) - ss) // 2) % mod)
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))
n = int(input())
A = list(map(int, input().split()))
Sum = sum(A)
square_sum = sum(map(lambda x:x*x, A))
print((Sum*Sum - square_sum)//2%(10**9+7))
# coding: utf-8
N= int(input())
A=list(map(int,input().split()))

cA = [A[-1]]

MOD = 10**9+7

for i in range(N-1):
    cA.append(cA[-1]+A[-2-i])

ans=0
cA.reverse()


for i in range(N-1):
    ans+=A[i]*cA[i+1]
    ans=ans%MOD
    
print(ans)
def square(list):
    return [i ** 2 for i in list]
m = 1000000007
n = int(input())
A = list(map(int, input().split()))
sq = square(A)
s1 = sum(A)
s2 = sum(sq)
 
result = (s1**2-s2)//2
print(result%m)
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
mod = int(1e9+7)

sum = 0
row = 0
for ii in range(N-1):
    i = N-2-ii
    row += A[i+1]
    row %= mod
    sum += A[i] * row
    sum %= mod

print(sum)
n = int(input())
a = list(map(int,input().split()))
sum = 0
ans = 0
dp=[]
for i in reversed(range(1,n)):
    sum += int(a[i])
    dp.append(sum % (10**9+7))

for i in range(n-1):
     ans += a[i] * dp[n-2-i]
     ans %= (10**9+7)
print(ans)
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
buf=0
s=0
for k in range(N-1):
    buf=(buf+A[N-1-k])%mod
    s=(s+A[N-2-k]*buf)%mod
print(s)
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)
N = int(input())
A = list(map(int, input().split()))
S = sum(A)%(10**9+7)
ans = 0
for i in range(N-1):
  S -= A[N-i-1]
  ans += S*A[N-i-1]%(10**9+7)
print(ans%(10**9+7))
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
ans=0
for i in A[:N-1]:
    s-=i
    ans+=s*i
    ans%=10**9+7
print(ans)
def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	S = sum(A)
	res = 0
	v = 10**9+7
	for i in range(N-1):
		S -= A[i]
		res += A[i] * S
	print(res%v)
resolve()
n = int(input())
a = [int(x) for x in input().split()]
pref = [0]*(n+1)
for i in range(n + 1):
    pref[i] = pref[i - 1] + a[i - 1]
answer = 0
for i in range(n - 1):
    answer += (pref[n] - pref[i + 1]) * a[i]
    answer %= (10 ** 9 + 7)
print(answer)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7

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

if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))
sum_mod=[0]
for i in range(N):
  sum_mod+=[(sum_mod[i]+A[i])%(10**9+7)]
ans=0
for i in range(N):
  ans=(ans+sum_mod[i]*A[i])%(10**9+7)
print(ans)
N = int(input())
Alist = list(map(int,input().split()))
M = 10**9+7
Asum = sum(Alist)
Answer = 0
for i in range(len(Alist)):
    Asum -= Alist[i]
    Answer += (Alist[i]%M)*(Asum%M)
    Answer = Answer%M
print(Answer)
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)
_ = input()
A = list(map(int, input().split()))
mod = 10**9 + 7

s = 0
a = 0
for _a in A:
  s += _a * a
  a = (a + _a) % mod
print(s % mod)
n = int(input())
A = list(map(int, input().split()))

S = sum(A)**2 - sum(map(lambda x:x**2, A))

print(S//2 % 1000000007)
N = int(input())
A = list(map(int, input().split()))

s = sum(A)
sumpro = 0

for a in A[:-1]:
	s -= a
	sumpro += a * s

print(sumpro % (10 ** 9 + 7))
N = int(input())
A = [int(a) for a in input().split()]
p = 10 ** 9 + 7

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

sum = 0
for i in range(0, N - 1):
	sum += (A[i] * (S[N - 1] - S[i])) % p
print(sum % p)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 7 + 10**9
    s = sum(A)
    s %= mod
    r = 0
    for i in range(N):
        s -= A[i]
        r += s * A[i]
        r %= mod
    return r
print(main())
n = int(input())
a = list(map(int,input().split()))

par = [0] * n
par[0] = a[0]

mod = 10**9 + 7

for i in range(1,n):
  par[i] = par[i-1] + a[i]
  par[i] = par[i] % mod
  
ans = 0
#print(par)

for i in range(n-1):
  ans += a[i] * (par[-1] - par[i])
  ans = ans % mod
  
print(ans%mod)
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

res = sum([a[i] ** 2 for i in range(n)])
s = sum(a)
ans = (s ** 2 - res) // 2
ans %= mod

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

sum_an = sum(an)
total = 0
for ai in an:
    total = total + ai * (sum_an - ai)
    sum_an = sum_an - ai
print(total % ((pow(10, 9) + 7)))
N = int(input())
n_list = list(map(int,input().split()))

result = 0

s = sum(n_list)
m = 10**9+7

for num in n_list:
    s -= num
    result += num * s % m
    result %= m

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


def mod(x):
    return x%(10**9+7)


sum_num = 0
ans = 0
for i in range(len(a)-1):
    idx = len(a)-i-1
    sum_num += a[idx]
    sum_num = mod(sum_num)
    ans += sum_num*a[idx-1]
    ans = mod(ans)
print(ans)