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-----
3
1 2 3

-----Sample Output-----
11

We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11.

Difficulty: introductory

Starter code:

Solutions:
(N), *D = [list(map(int, s.split())) for s in open(0)]
V = D[0]
A = V.pop(N[0]-1)
M = 1000000000 + 7
R=0
for value in reversed(V):
    R = R + ((A) * value) % M
    A = A + value
print(R % M)

def main():
   N=int(input())
   CONST= 10**9+7
   Output = 0
   lis = list(map(int,input().split()))       
   lis.sort()
   SumLis = [0]*N
   for i,item in enumerate(lis):
      SumLis[i] += SumLis[i-1]+item
   for i,item in enumerate(lis):
      Output += lis[i] * (SumLis[-1]-SumLis[i])
      Output %= CONST
   print(Output)

      
def __starting_point():
    main()


__starting_point()

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

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

ans = 0
MOD = 10**9 + 7
A.reverse()
ruisekiwa = cumsum(A)
ruisekiwa.reverse()
A.reverse()

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

print(ans)

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

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

for x in a:
  s -= x
  ans += s * x
  
print(ans%mod)

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

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

for x in a:
  s -= x
  ans += s * x
  ans %= mod
  
ans %= mod
print(ans)

CONST = 10 ** 9 + 7
N = int(input())
numbers = list(map(int, input().split()))
r = 0


def cumsum(xs):
    result = []
    for i in range(len(xs)):
        if i == 0:
            result.append(xs[0])
        else:
            result.append(result[-1] + xs[i])
    return result


numbers.reverse()
num_sum = cumsum(numbers)
num_sum.reverse()
numbers.reverse()
del num_sum[0]
for i in range(N-1):
    r += (numbers[i]*num_sum[i])%CONST
print((r % CONST))


import math
prime = [True for i in range(10**6+1)]
def SieveOfEratosthenes(n): 
	p = 2
	while (p * p <= n): 
		if (prime[p] == True):
			for i in range(p * p, n+1, p): 
				prime[i] = False
		p += 1

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





__starting_point()

import math
prime = [True for i in range(10**6+1)]
def SieveOfEratosthenes(n): 
	p = 2
	while (p * p <= n): 
		if (prime[p] == True):
			for i in range(p * p, n+1, p): 
				prime[i] = False
		p += 1

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




3
__starting_point()

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

# result = 0
# for i in range(N):
#     for j in range(N):
#         if i < j:
#             result += (A[i] * A[j]) % mod

# print(result % mod)

# result = 0
# for i in range(N):
#     j = i+1

#     while(j < N):
#         result += (A[i] * A[j]) % mod
#         #print(i, " : ", j)
#         j += 1

# print(result % mod)

A_sum = sum(A)
result = 0
for i in range(N):
    A_sum = A_sum - A[i]
    result += (A[i] * A_sum) % mod

print(result % mod)

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

N = int(input())
A = list(map(int, input().split()))
s = 0
s2 = sum(A)

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

answer = s % (10**9+7)
print(answer)

n = int(input())
a = list(map(int,input().split()))
suma = sum(a)
c = 0
for num in a:
  c += num**2
print((suma**2-c)//2%(10**9+7))

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


import numpy as np
n=int(input())
a= sorted(map(int,input().split()))
b=np.cumsum(a,dtype=np.int64)
c=0
mod=10**9+7
for i in range(n-1):
    ## a[i]*(全累積和 - i以下の累積和)
    c+=(a[i]%mod)*((b[-1]-b[i])%mod)
    c%=mod
print(c)

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

CONST = 10 ** 9 + 7
N = int(input())
numbers = list(map(int, input().split()))
r = 0


def cumsum(xs):
    result = []
    for i in range(len(xs)):
        if i == 0:
            result.append(xs[0])
        else:
            result.append(result[-1] + xs[i])
    return result


numbers.reverse()
num_sum = cumsum(numbers)
num_sum.reverse()
numbers.reverse()
del num_sum[0]
for i in range(N-1):
    r += (numbers[i]*num_sum[i])%CONST
print((r % CONST))


n = int(input())
arr = input()
ar = list(map(int,arr.split(' ')))
sum=0
s=0
mod=1000000007
for i in range(0,n):
    sum=sum+(ar[i]*ar[i])
    s=s+ar[i]
s=s*s
print(((s-sum)//2)%mod)

N = int(input())
A = list(map(int, input().split()))
print((sum(A)**2-sum(a**2 for a in A))//2%(10**9+7))

n = int(input())
A = [int(x) for x in input().split()]
mod = 10**9+7
a_cum = [0] * (n+1)
# 累積和の計算
for i in range(n):
    a_cum[i + 1] = a_cum[i] + A[i]
ans = 0
for i in range(len(A)-1):
    # a_cum[n]は全ての合計と同義。a_cumはindexが1つずれているので以下のようになる。 
    ans += A[i] * (a_cum[n] - a_cum[i+1]) % mod
ans %= mod
print(ans)

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

lst_sm=sum(alst)
sm=lst_sm**2
for i in range(n):
    sm-=alst[i]**2
sm//=2
print((sm%mod))


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

print(ans)

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())),dtype=np.int64)
MOD = 10**9+7
B = np.cumsum(A[N-1:0:-1])[::-1]
B %= MOD
print((np.sum(A[:N-1] * B % MOD) % MOD))


n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ans = 0
sub = 0

for i in range(n):
  ans += a[i]*s
  
for j in range(n):
  sub += a[j]**2
    
print(((ans-sub)//2)%(10**9 + 7))

def cusum(a):
    cusum = [a[0]]
    for i in range(len(a)-1):
        cusum.append(cusum[i] + a[i+1])
    return cusum


def solve1(n, a):
    ans = 0
    mod = 10**9 + 7
    cusum_a = cusum(a)

    for i in range(n):
        ans += a[i] * (cusum_a[-1] - cusum_a[i])
        """
        print(a[i], "*",
              "(", a[i+1:], "=", (cusum_a[-1] - cusum_a[i]), ")",
              "=", a[i] * (cusum_a[-1] - cusum_a[i]))
        """
        ans %= mod

    return ans


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


import sys
# from numpy import cumsum
input = sys.stdin.readline
n = int(input())
a = [int(_) for _ in input().split()]
mod = 10**9 + 7
ans = 0
s = [0]
a_ = a[::-1]
for i in range(len(a_)-1):
  s.append(s[i]+a_[i])
s = s[::-1]
s.pop(len(s)-1)
# print(s)
for i in range(len(a)-1):
  ans += a[i] * s[i]
  ans = ans % mod
print(ans)

CONST = 10 ** 9 + 7
N = int(input())
numbers = list(map(int, input().split()))
r = 0


def cumsum(xs):
    result = []
    for i in range(len(xs)):
        if i == 0:
            result.append(xs[0])
        else:
            result.append(result[-1] + xs[i])
    return result


numbers.reverse()
num_sum = cumsum(numbers)
num_sum.reverse()
numbers.reverse()
del num_sum[0]
for i in range(N - 1):
    r += (numbers[i] * num_sum[i]) % CONST
print((r % CONST))


n = int(input())
a = list(map(int,input().split()))
s = sum(a)
x = [i**2 for i in a]
x = sum(x)
ans = (s**2-x)//2
print(ans%(10**9+7))

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

# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

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

cumsum = [0] * (len(AN) + 1)
for i in range(1, N + 1):
    cumsum[i] = cumsum[i - 1] + AN[i - 1]

ans = 0
for i in range(1, N):
    ans += AN[i] * cumsum[i]
    ans %= MOD


print(ans)


n = input()
a = list(map(int,input().split()))
sum = 0
msum = 0
for i in a:
  sum += i
  msum += i*i
ans = int((sum*sum - msum)//2)
print(int(ans%1000000007))

n = int(input())
l = list(map(int,input().split()))
A = sum(l)-l[0]
ans = 0
for i in range(len(l)) :
    ans += l[i]*A
    
    if A == l[-1] :
        break
    else :
        A -= l[i+1]

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

#abc177c
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
t=sum([x*x for x in a])
print(((s*s-t)//2%(10**9+7)))


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


N = int(input())
A = cin()

total = 0
store = 0
for i in range(N - 1):
    store += A[N - i - 1]
    total += A[N - i - 2] * store
print((total % (pow(10, 9) + 7)))


N=int(input())
b = 0
a = list(map(int, input().split()))
c = 0
for i in range(0,N):
  c = c + a[i]
for i in range(0,N):
  c = c - a[i]
  b = (b + a[i] * c) %(10**9+7)
print(b)

N = int(input())
mod = 10**9 + 7
A = list(map(int, input().split()))
Asum = sum(A)
ans = 0
for a in A:
  Asum -= a
  ans += a*Asum % mod
print(ans % mod)

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

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

MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
sum_of_all=sum(A)**2
sum_of_diagonal=0
for i in range(N):
  sum_of_diagonal+=A[i]**2
print((sum_of_all-sum_of_diagonal)//2%MOD)

CONST = 10 ** 9 + 7
N = int(input())
numbers = list(map(int, input().split()))
r=0

def cumsum(xs):
    result = []
    for i in range(len(xs)):
        if i == 0:
            result.append(xs[0])
        else:
            result.append(result[-1] + xs[i])
    return result
numbers.reverse()
num_sum = cumsum(numbers)
num_sum.reverse()
numbers.reverse()
del num_sum[0]
for i in range(N-1):
    r+=(numbers[i]*num_sum[i])%CONST
print(r%CONST)

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

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

n = int(input())
c = list(map(int, input().split()))
c_ans = []
ans = 0

#print(c)
for i in range(n):
  ans += c[i]
  #print(ans)
  c_ans.append(ans)
    
re_ans = 0
#print(c_ans)

for i in range(n):
  re_ans += c[i] * (c_ans[n-1] - c_ans[i])

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

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

total = (sum(A))**2
for i in range(n):
     total -= (A[i])**2
ans = (total//2)%(10**9+7)
print(ans)


from functools import reduce
from operator import add

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

def cum(total, a):
    total.append(a + total[-1])
    return total

cumsum = reduce(cum, A, [0])
cum_last = cumsum[-1]

p = 1000000007

def i_fixed(i):
    return (A[i] * (cum_last - cumsum[i+1])) % p

def solve():
    return map(i_fixed, range(N-1))

print(sum(solve()) % p)

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

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

print(ans%mod)

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

suma = sum(a)
ans = 0
for i in range(len(a)):
  suma = suma - a[i]
  ans += suma * a[i]
ans = ans % (10**9+7)
print(ans)

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

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())),dtype=np.int64)
MOD = 10**9+7
B = np.cumsum(A[N-1:0:-1])[::-1]
B %= MOD

ans = 0
for i,j in zip(A[:N-1], B):
    ans += i*j
    ans %= MOD
print(ans)
# ans = 0
# for i in range(N-1):
#     ans += A[i] * B[i]
#     ans %= MOD
#
# print(ans)


def __starting_point():

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

    cumA = [A[0]]
    for i in range(1,N):
        cumA.append(cumA[-1] + A[i])
    
    count = 0
    for i in range(N - 1):
        count += A[i] * ( cumA[N-1] - cumA[i] )
    
    print(count % (10**9 + 7))
__starting_point()

def main():
    N = int(input())
    mod = 10**9 + 7
    
    a = list(map(int, input().split()))

    ans = 0
    s = 0
    
    for i in range(1, N):
        s += a[i]
    
        
    for i in range(1, N):
        ans += (a[i-1] * s) % mod
        s -= a[i]
            
    print(ans % mod)
            
    
    
def __starting_point():
    main()
__starting_point()

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())),dtype=np.int64)
MOD = 10**9+7
B = np.cumsum(A[N-1:0:-1])[::-1]
B %= MOD
print((np.sum((A[:N-1] * B) % MOD) % MOD))


N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7

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

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

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

mod = 10**9+7

sum_list = []
sum_ = 0
for i in range(len(A)-1):
    sum_ += A[i+1]
    sum_list.append(sum_)
    
len_ = 0
for i in range(len(A)-1):
    len_ += (A[i+1] * (sum_list[-1] - sum_list[i]) )% mod

print(((len_+A[0]*sum_list[-1])%mod))


N, = map(int,input().split())
A = list(map(int,input().split()))
su = A[N-1]
suu = su*A[N-2]
for i in reversed(range(1,N-1)):
  su+=A[i]
  suu+=(su*A[i-1])
print(suu%(10 ** 9+7))

import sys
n=int(input())
a=[int(x) for x in input().split()]

s=0
for i in range(n):
    s+=a[i]
c=0
sum=0
for k in range(n-1):
    c+=a[k]
    co=s-c
    sum+=a[k]*co

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


from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]

sa = sum(A)
ans = 0

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

print(ans)

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

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

s = 0
sum = 0
ans = 0

for i in range(n):
  s += A[i]

for j in range(n-1):
  s -= A[j]
  sum += A[j] * s

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

MOD = 10 ** 9 + 7  # MODは変数に入れてしまったほうが打ち間違えなくていいです

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

S = sum(A) % MOD
ans = 0

# A_Nも含まれてしまいますが、そのときはs=0なので問題ありません
for x in A:
    S -= x  # 自分と自分自身を掛けないように、先に引く必要があります
    S %= MOD  # MODはいちいち取っておくといいです
    ans += S * x
    ans %= MOD

ans %= MOD  # この行は完全に不要ですが、最後だけMODを取り忘れてWAになるミスは非常によくあるので、必要以上に取っておくと安心できます
print(ans)

p = 10**9 + 7
n = int(input())
aa = list(map(int, input().split()))
s = 0
for a in aa:
  s += a**2

sa = sum(aa)
b = sa*sa
ans = (b-s)//2

print(ans % p)

import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
mod = 998244353

n = ri()
a = rl()
cs = 0
li = []
for i in a:
    cs+=i
    li.append(cs)
sum_ = sum(a)
ans = 0
for i in range(len(a)):
    ans += a[i]*(sum_-li[i])%MOD
print(ans%MOD)

mod = 1000000000+7

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


sum_ = sum(As)
ret = 0
for i in range(n-1):
    sum_ -= As[n-1-i]
    ret += sum_ * As[n-1-i]
    ret %= mod

print(ret)

import numpy as np
n=int(input())
a= sorted(map(int,input().split()))
b=np.cumsum(a,dtype=np.int64)
c=0
mod=10**9+7
for i in range(n-1):
    c+=(a[i]%mod)*((b[-1]-b[i])%mod)
    c%=mod
print(c)

n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
b = sum(a)
c = sum([i*i for i in a])
ans = ((b**2 - c)//2)%mod
print(ans)

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

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())),dtype=np.int64)
MOD = 10**9+7
B = np.cumsum(A[N-1:0:-1])[::-1]
B %= MOD
print((np.sum((A[:N-1] * B) % MOD) % MOD))


n = int(input())
li = list(map(int, input().split()))
mod = 10**9 + 7
sm = sum(li)
mul = sum([i**2 for i in li])
ans = ((sm ** 2 - mul) // 2) % mod
print(ans)


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

# 解説を読んで解いた

# 累積和の計算

sm = [0]
for i in range(N):
  sm.append(sm[i]+A[i])

# 累積和を使った解答
ans = 0
for j in range(N):
  ans += A[j]*(sm[N]-sm[j+1])
  
print(ans % (10**9+7))

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 -= A[i]
    S %= MOD
    ans += (A[i] % MOD) * S
    ans %= MOD
    
print(ans)

N=int(input())
A=[0]*N
S=[0]*(N+1)
A=list(map(int,input().split()))
mod=10**9+7

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

cnt=0
for j in range(N-1):
    cnt+=A[j]*(S[N]-S[j+1])%mod

print(cnt%mod)

import numpy as np
n=int(input())
a= sorted(map(int,input().split()))
b=np.cumsum(a,dtype=np.int64)
c=0
mod=10**9+7
for i in range(n-1):
    c+=(a[i]%mod)*((b[-1]-b[i])%mod)
    c%=mod
print(c)

import sys


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] %= MOD
    S = sum(A)
    answer = 0
    for i in range(N):
        S = S - A[i]
        answer += A[i] * S
        answer %= MOD
    print(answer)


def __starting_point():
    main()

__starting_point()

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

mod = 1000000007
sum = 0
ans = 0
for i in range(n):
	ans = (ans + a[i]*sum) % mod
	sum += a[i]
print(ans)


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

ans = 0

MOD = 10 ** 9 + 7

sum_A = sum(A)

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

print((ans % MOD))


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

MOD = 10**9 + 7
s = 0

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

print(ans)

mod = 10 ** 9 + 7
N = int(input())
A = list(map(int,input().split()))
sum_of_all = sum(A)**2
sum_of_diagonal = 0
for i in range(N):
  sum_of_diagonal += A[i]**2
print((sum_of_all - sum_of_diagonal) // 2 % mod)

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

M = 10**9 + 7

Ans = 0

T = sum(A)

for i in range(N-1):
    T -= A[i]
    Ans += A[i] * T
    Ans %= M

print(Ans)


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

import numpy as np
import itertools as it
n = int(input())
a = list(map(int, input().split()))
_sum = 0
ans = 0
mod = 1000000007
  
for i in range (n):
  _sum += a[i]
  _sum %= mod

for i in range (n):
  _sum -= a[i]
  if _sum < 0:
    _sum += mod
  ans += a[i] * _sum
  ans %= mod

print(ans)

import itertools

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

lis = list(itertools.accumulate(reversed(a)))

for i in range(n-1):
  ans += a[i]*lis[n-2-i]
    
print(ans%(10**9 + 7))

n = int(input())
a = list(map(int, input().split()))
lim = (10 ** 9) + 7
ans = 0
temp = a[-1]
for i in range(2,n+1):
  ans += a[-i] * temp
  temp += a[-i]
#  print("ans = {} temp = {}".format(ans,temp))

print(ans%lim)

n = int(input())
li = list(map(int,input().split()))
s = [li[0]]
ans = 0
m = 10**9 +7
for i in range(n-1):
    s.append(li[i+1] + s[i])

for j in range(n-1):
    ans += (li[j] * (s[n-1]-s[j])) % m

print(ans%m)

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
  
ans %= mod

print(ans)

mod = 10**9 + 7
n = int(input())
a = [int(i) for i in input().split()]
s = sum(a)
out = 0
for i in a:
  s -= i
  out += s * i
  out %= mod
print(out)

N = int(input())
num = list(map(int, input().split(' ')))
ans = 0
total = sum(num)
MOD = 10 ** 9 + 7
for a in num:
    total -= a
    ans += a * total 
    ans %= MOD
ans %= MOD
print(ans)

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

mod = (10**9)+7
ans = 0
sums = [0]*N
sums[0] = A[0]
for i in range(1, N):
    sums[i] = sums[i-1] + A[i]

for j in range(N):
    ans += A[j]*(sums[-1]-sums[j])

print(ans%mod)

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

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

print(ans%mod)

n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
rr = [0 for i in range(n + 1)]

for i in range(n):
    rr[i + 1] = (A[i] + rr[i]) % mod

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

print((ans % mod))


import itertools
n = int(input())
A = list(map(int, input().split()))
A2=[]
for i in range(n):
    A2.append(A[n-1-i])

acc_A2 = list(itertools.accumulate(A2))
mod = (10**9)+7

goukei = 0

for i in range(n-1):
    goukei += A[i]*acc_A2[n-2-i]

print(goukei%mod)

import numpy as np
n=int(input())
a= sorted(map(int,input().split()))
b=np.cumsum(a)
c=0
mod=10**9+7
for i in range(n-1):
    c+=int(a[i])*(int(b[-1])-int(b[i]))
    c%=mod
print(c)

CONST = 10 ** 9 + 7
N = int(input())
numbers = list(map(int, input().split()))
r=0

def cumsum(xs):
    result = []
    for i in range(len(xs)):
        if i == 0:
            result.append(xs[0])
        else:
            result.append(result[-1] + xs[i])
    return result
numbers.reverse()
num_sum = cumsum(numbers)
num_sum.reverse()
numbers.reverse()
del num_sum[0]
for i in range(N-1):
    r+=(numbers[i]*num_sum[i])%CONST
print((r%CONST))


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

n = int(input())
A = [int(i) for i in input().split()]

tmp = 0
res = 0

res = sum(A) ** 2
for i in range(n):
    res -= A[i] ** 2
res = res // 2 % MOD

print(res)


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

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

sum = 0
s_list=[]
ans = 0

for i in range(n):
    sum += a_list[i]
    s_list.append(sum)

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

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


n = int(input())
a = list(map(int,input().split()))
a.sort()
s = sum(a)
x = [i**2 for i in a]
x = sum(x)
ans = (s**2-x)//2
mod = 10**9+7
print(ans%mod)

import sys

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

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


mod = 10**9+7
n = int(input())
l = list(map(int, input().split()))
ans = []
a = sum(l)
for i in range(len(l)):
  a = a - l[i]
  ans.append(l[i] * a)

print((sum(ans)%mod))




n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
sm=sum(a)
mul=sum(i**2 for i in a)
ans=((sm ** 2 - mul) // 2) % mod
print(ans)