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):
N = int(input())
A = list(map(int, input().split()))
B = sum(map(lambda x: x ** 2, A))

print(((sum(A) ** 2 - B) // 2) % (10 ** 9 + 7))

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

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

B = list(map(lambda x: x ** 2, A))

SA = sum(A)
SB = sum(B)

print(((SA * SA - SB) // 2) % mod)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
t=sum(a)
ta=[0]*n
for i in range(n):
  ta[i]=t
  t=t-a[i]
ans=0
for i in range(0,n-1):
  ans=ans+(a[i]*ta[i+1])
  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-1):
    S -= A[i]
    ans = (ans + S*A[i])%MOD
    
print(ans)

Solution (Python):
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

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

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print((tmp*tmp-tmp2)//2%1000000007)

Solution (Python):
mod = 1000000007
N = int(input())
ruiseki = []
A = list(map(int, input().split()))
sum = 0

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

ruiseki.append(sum - A[0])
if(ruiseki[0] < 0): ruiseki[0] += mod

for i in range(1,N-2):
  ruiseki.append(ruiseki[i-1] - A[i])
  if(ruiseki[i] < 0): ruiseki[i] += mod

ans = 0

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

ans += (A[N-2]%mod)*(A[N-1]%mod)%mod
ans = ans%mod
print(ans)

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

mod = 1000000007
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()))
S = [0]*n
for i in range(0, n):
    if i > 0:
        S[i] = S[i-1] + a[i]
    else:
        S[i] = a[i]
ans = int(0)
m = int(1000000007)
for i in range(0, n):
    ans = (ans + (a[i] * (S[n-1]-S[i]))) % m
print(ans)

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

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

Solution (Python):
import itertools

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

acc = list(itertools.accumulate(A))
ans = 0
mod = 10**9 + 7

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

print(ans%mod)

Solution (Python):
import copy
mod=10**9+7
def calc(nums,n):
    if n==2:
        return ((nums[0]%mod)*(nums[1]%mod))%mod
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save%mod+nums[i+1]%mod)%mod
        save=s%mod
       
    ans=0  
    
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
    





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

gokei = sum(A) ** 2
for i in range(len(A)):
    gokei -= A[i] * A[i]
gokei = gokei // 2
ans = gokei % 1000000007
print(ans)

Solution (Python):
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)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)
    ans = s * s
    for a in A: ans -= a * a
    print((ans // 2) % mod)


if __name__ == "__main__":
    main()

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

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

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

S1 = sum(A)
S2 = sum(map(lambda x:x*x, A))
         
print((S1 * S1 - S2) // 2 % 1000000007)

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

for i in list1:
  sums -=i
  ans +=sums*i%mod
  
print(ans%mod)

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

mod = 10 ** 9 + 7
total = 0
y = sum(list1)

for i in range(0,n-1):
    y = y- list1[i]
    total += list1[i] * y % mod

total = total % mod
print(total)

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

ans = sum(a)**2

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

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

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

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

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

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

ans = 0
den = int(1e9 + 7)
sum_a = [0 for i in range(len(a))]
sum_a[-1] = a[-1]
for i in range(len(a) - 1, 1, -1):
    sum_a[i - 1] = sum_a[i] + a[i - 1]
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum_a[i + 1]) % den

print(ans)

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

mod = 1000000007

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

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

print(ans % mod)

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

Solution (Python):
N = int(input())
ls = list(map(int, input().split()))
mod = 10**9+7
total = sum(ls)
sq_power = sum(map(lambda x:x*x%mod, ls))
ans = (total**2 - sq_power)%mod
ans2 = 2
for _ in range(9):
    ans2 = (ans2**10)%mod
ans2 *= 2**5 % mod
print(ans*ans2%mod)

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

tmp = A[-1]
cum = [tmp]
for i in range(1, N-1)[::-1]:
    tmp += A[i]
    cum.append(tmp)
    
cum = cum[::-1]
ans = 0
for i in range(N-1):
    ans += cum[i]*A[i]
    ans %= mod

print(ans)

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

ans = 0
latsum = sum(a)-a[0]
for i in range(n-1):
    ans += a[i]*latsum
    ans %= int(1e9+7)
    latsum -= a[i+1]
        
print(ans)

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


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

    
if __name__ == "__main__":
    main()

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

sum_A = sum(A)
ans = 0

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

print(ans%mod)

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

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

for i in range(N-1,-1,-1):
    su+= (A[i] * a) % mod
    a += A[i]
print(su % mod)

Solution (Python):
import numpy as np
N = int(input())
A_str = input()
A_str_list = A_str.split()
A = np.array([int(A_str_list[i]) for i in range(N)])
sum = 0
mod = 1000000007
res = np.cumsum(A)
res = [np.mod((res[-1]-res[i]), mod) for i in range(N)]

for i in range(N):
    sum += np.mod(res[i]*A[i], mod)
print(np.mod(sum, mod))

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

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

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

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

for i in range(N-1,-1,-1):
    su+= A[i] * a
    a += A[i]
print(su % mod)

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

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

Solution (Python):
import math

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

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

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

ans = ans % MOD
print(ans)

Solution (Python):
def c_sum_of_product_of_pairs(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    cumsum = [0]
    for a in A:
        cumsum.append(cumsum[-1] + a)
    return sum([(cumsum[N] - cumsum[i + 1]) * A[i] for i in range(N)]) % MOD

print(c_sum_of_product_of_pairs())

Solution (Python):
n = int(input())
sz = [int(x) for x in input().split(" ")]

ans = sum(sz)*sum(sz)

for i in sz :
    ans -= i*i

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

print(int(ans))

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

print(ans % mod)

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
d = []
cnt = 0
ans = 0
for i in range(n-1,0,-1):
	cnt+=a[i]
	d.append(cnt)
d = d[::-1]
for i in range(n-1):
	ans+=d[i]*a[i]
print(ans%(10**9+7))

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

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

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

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

ans = ans % MOD
print(ans)

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

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

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

ans = ans % MOD
print(ans)

Solution (Python):
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)

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

Solution (Python):
from itertools import accumulate

N = int(input())

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

B = list(accumulate(A))

d = 10**9+7
s = 0

for i in range(N):
    s += (A[i]*(B[-1]-B[i])) % d
    
print(s % d)

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

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

mod = 10 ** 9 + 7

temp = 0

for i in range(N):

    temp += (A[i] ** 2) 

print(((((sum(A) ** 2) ) - (temp)) // 2) % mod)

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

Solution (Python):
def c_sum_of_product_of_pairs(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    total = sum(A)
    cumsum = [0]
    for i in range(N):
        cumsum.append(cumsum[-1] + A[i])

    return sum([(total - cumsum[i]) * A[i - 1] for i in range(1, N)]) % MOD

print(c_sum_of_product_of_pairs())

Solution (Python):
n = int(input())
la = list(map(int, input().split()))
MOD = 10**9+7
s1 = sum(la)
s2 = sum([x**2 for x in la])
ans = (s1*s1-s2)//2%MOD
print(ans)

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

MOD = 10**9 + 7

sum_A = [0] * N
sum_A[0] = A[0]

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

print(sum([sa*a for sa,a in zip(sum_A[:-1], A[1:])]) % MOD)

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

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

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

print(ans % 1000000007)

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

s_1 = 0
s_2 = 0
m = 10 ** 9 + 7
for i in range(n):
    s_1 += a[i] % m
    s_2 += (a[i] ** 2) % m
s = (s_1 * s_1 - s_2) * pow(2, m - 2) % m
print(s)

Solution (Python):
N = int(input())
x = list(map(int, input().split()))
s = sum(x) - x[0]
ans = 0

for i in range(N-1):
  ans = ans + x[i]*s
  s = s - x[i+1]
ans = ans % 1000000007
  
  
print(ans)

Solution (Python):
p = (10 ** 9 + 7) * 2
N = int(input())
A = [int(x) for x in input().split()]
A2 = [(x ** 2) % p for x in A]
result = (((sum(A) % p) ** 2 - sum(A2) % p) % p) / 2
print(int(result))

Solution (Python):

from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n = int(input())
a = get_array()

pre_sum = [0]

for i in range(n-1,-1,-1):
    pre_sum.append(pre_sum[-1]+a[i])

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

print(ans)

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

s = sum(A)

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

print(ans%mod)

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

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

ans = 0
mod = 1000000007

a = [-1] + a
pre = [0]

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

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

print(ans)

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

ans = 0
sa = sum(a)%mod

for i in a:
    sa -= i
    sa %= mod
    ans += i*sa%mod
    ans %= mod
print(ans)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

MOD = 10**9 + 7
ans = 0
s = 0
i = N - 1
for n in range(N - 2, -1, -1):
    s += As[i]
    s %= MOD
    i -= 1
    ans += s * As[n]
    ans %= MOD

print(ans)

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

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n = int(input())
num_list = list(map(int, input().split()))
mod = int(1e+9+7)
cumsum_list = np.cumsum(num_list[::-1])[::-1][1:]
all_sum = sum(num_list)
score = 0
for i in range(n-1):
    
    score += (num_list[i] * (cumsum_list[i]%mod)) % mod
print(score % mod)

Solution (Python):
import numpy as np

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

sum = A.sum() % mod




sum2 = 0

for x in A:
  sum2 += x**2
  sum2 %= mod

ans = (sum**2 - sum2) % mod

if ans%2==1 : ans += mod
ans //= 2
ans %= mod
print(int(ans))

Solution (Python):
import numpy as np
n = int(input())
num_list = list(map(int, input().split()))

mod = int(1e+9+7)
cumsum_list = np.cumsum(num_list[::-1])[::-1][1:]
all_sum = sum(num_list)
score = 0
for i in range(n-1):
    
    
    all_sum -= num_list[i]
    score += (num_list[i] * all_sum) % mod
print(score % mod)

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

for j in range(0,len(A)):
    c+=A[j]

for i in range(0,len(A)):
        c=c-A[i]
        b+=A[i]*c
        
print(b%(10**9+7))

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

rs=[0]*n
rs[0]=l[-1]
j=1
for i in range(n-2,-1,-1):
    rs[j]=rs[j-1]+l[i]
    j+=1
rs=rs[::-1]

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

Solution (Python):
mod = 10**9+7
N = int(input())
a = list(map(int, input().split()))
sum_a = 0
sum_a2 = 0
for x in a:
  sum_a += x
  sum_a2 += x**2

ans = ((sum_a**2 - sum_a2))//2
print(ans%mod)

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

a_list_reverse = a_list[::-1]


rusekiwa = [0] * (len(a_list_reverse) - 1)
sum_v = 0
for i in range(len(a_list_reverse) - 1):
    sum_v += int(a_list_reverse[i])
    rusekiwa[i] = sum_v


ans = 0
for i in range(len(a_list) - 1):
    v = int(a_list[i]) * rusekiwa[-1 - (i)]
    
    
    ans += v
    ans = ans % (10 ** 9 + 7)


print(ans)

Solution (Python):
Q = 10**9+7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    S = sum(A)%Q
    T = sum( [a*a for a in A])%Q
    print((S*S%Q-T)*pow(2,Q-2,Q)%Q)
if __name__ == '__main__':
    main()

Solution (Python):
p=(10**9+7)*2
n=int(input())
A=[int(x) for x in input().split()]
A2=[(x**2)%p for x in A]
result=(((sum(A)%p)**2 - sum(A2)%p)%p)/2
print(int(result))

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

Solution (Python):
N = int(input())
As = list(map(int,input().split()))
sums = 0
moder = 1000000007
s=[0 for i in range(N-1)]
s[-1] = As[-1]
for i in range(N-2):
  s[-(i+2)] = s[-(i+1)]+As[-(i+2)]

for i in range(N-1):
  sums+= (As[i]*s[i])%moder
print(sums%moder)

Solution (Python):

def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

    square_S = sum(A) ** 2 % mod
    diagonal = sum([x ** 2 % mod for x in A]) % mod
    
    print(((square_S - diagonal) % mod * pow(2, mod - 2, mod)) % mod)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
A = tuple(map(int,input().split(" ")))
ans = 0

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

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

Solution (Python):
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)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
SUM = sum(A) % MOD
ans = 0

for n in A:
    SUM -= n
    SUM %= MOD
    ans += SUM * n
    ans %= MOD

print(ans)

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

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

ans = (S*S - S_2)//2 

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

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

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

answer = 0
a_sum = sum(A)
mod = 10**9+7

for i in range(N-1):
  a_sum -= A[i]
  answer += a_sum * A[i]
print(str(answer % mod))

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

ans = 0
for i, a in enumerate(reversed(A[1:])):
    ans += Acum[n-i-2]*a
    ans %= MOD
print(ans)

Solution (Python):
def main():
    n = int(input())
    a = []
    sum = 0             
    ans = 0             
    mod = 1_000_000_000 + 7
    x = list(map(int, input().split()))
    for i in range(n):
        sum += x[i]           
        a.append(x[i])
    
    sum % mod
    
    for i in range(n):
        sum -= a[i]
        if sum < 0:
            sum += mod
        ans += sum * a[i]
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

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

edge = sum(x)
print((edge**2 - sum([X*X for X in x]))//2 % (10**9+7))

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
S = sum(A)
T = sum(map(lambda x: x**2, A))
print((S**2-T)//2 % (10**9+7))

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

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(mod // 2) % mod * res % mod)

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

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

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

mod = int(1e9+7)
suffix_sum = sum(a)
ans = 0

for ai in a:
  suffix_sum -= ai
  ans += ai*suffix_sum
  ans %= mod

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)**2
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)

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

from itertools import accumulate
c=list(accumulate(a))
mod=10**9+7
ans=0
for i in range(n-1):
    ans+=a[i]*(c[n-1]-c[i])
    ans%=mod
print(ans)

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

answer = 0
x = 0
for i in range(len(A) - 1):
  x += A[i]
  answer +=  (x * A[i + 1])

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

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

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

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

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

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

Solution (Python):
def main():
    n = int(input())
    arr = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    sq = sum(num*num for num in arr)
    S = sum(arr)
    print(((S*S-sq)//2)%mod)

if __name__ == "__main__":
    main()

Solution (Python):
_ = input()
ans = b = 0
for a in map(int, input().split()):
    ans += a * b
    b += a
print(ans % (10**9 + 7))

Solution (Python):
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)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
MOD = 1000000007
B=0
tem = sum(A)
for i in range(len(A)):
    tem -= A[i]
    B+= (A[i]%MOD)*(tem%MOD)
print(B%MOD)

Solution (Python):
def main():
    n = int(input())
    a = []
    sum = 0             
    ans = 0             
    mod = 1_000_000_000 + 7
    x = list(map(int, input().split()))
    for i in range(n):
        sum += x[i]           
        a.append(x[i])
    
    for i in range(n):
        sum -= a[i]
        ans += sum * a[i]
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

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

ans=0
total=0
t=sum(x)

for i in range(n):
 
  t=t-x[i]
  total=total+x[i]*(t)
  
   
    
print(total %1000000007)

Solution (Python):

from itertools import accumulate

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

    acc = list(accumulate(A))
    mod = 10**9 + 7

    ans = 0

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

    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [a[0]]
ans = 0
mod = 1000000007

for i in range(1,n):
  b.append(b[-1]+a[i])

for i in range(1,n):
  ans += a[n-i]*b[n-i-1]
  ans = ans % mod
  
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 a[:n - 1]:
    s -= i
    ans += s * i
    ans %= 10 ** 9 + 7
print(ans)

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

s = sum(a) ** 2
t = sum(ai ** 2 for ai in a)
ans = (s - t) * pow(2, MOD - 2, MOD)
ans %= MOD
print(ans)

Solution (Python):
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)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
result = 0
sum = arr[0]
for i in range(1,len(arr)):
    result += (sum*arr[i])
    sum+=arr[i]
print(result%1000000007)

Solution (Python):
n = int(input())
ar = list(map(int,input().split(" ")))
sm = sum(ar)
count = 0
for i in range(n-1):
    sm -= ar[i]
    count += ar[i] * sm
print(count % (10 ** 9 + 7))

Solution (Python):
_ = input()
MOD = 10**9 + 7
ans = b = 0
for a in map(int, input().split()):
    ans += a * b
    ans %= MOD
    b += a
print(ans)

Solution (Python):
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)

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

"""
allsum = 0
for i in range(n-1):
    allsum += a[i] * sum(a[i+1:])
print(allsum % (10**9+7))
"""
s, s2 = 0, 0
for i in range(n):
    s += a[i]
    s2 += a[i] * a[i]
print(((s*s - s2)//2) % (10**9+7))

Solution (Python):
n = int(input())
A = [*map(int, input().split())]
MOD = 10**9 + 7
ans = b = 0
for a in A:
    ans += a * b
    ans %= MOD
    b += a
print(ans)

Solution (Python):
from itertools import accumulate

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

a = list(accumulate(lis))

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

print(ans)

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
t = sum(A)
x = t - A[0]
mod = 10 ** 9 + 7
ct = 0
for i in range(N-1):
    ct += A[i] * x
    x = x - A[i+1]

print((ct % mod))
int((ct % mod))

Solution (Python):
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)

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

suma = sum(A_list)

res = 0
for a in A_list:
    suma -= a
    res += suma * a

print(res%MOD)

Solution (Python):
n = int(input())
A = [*map(int, input().split())]
MOD = (10**9)+7
sum_a = sum(A)
ans = 0
for a in A[:n-1]:
    sum_a -= a
    ans += a * sum_a
    ans %= MOD
print(ans)

Solution (Python):
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)

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

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

s = sum(a)
b = 10**9+7
ans = 0
for i in a:
  s -= i
  ans += i*(s%b)
  ans %= b
print(ans)

Solution (Python):
N = input()
a_list = [int(i) for i in input().split(' ')]
mod = 1000000007
 
sum = 0
for i in a_list:
  sum += i
 
output_sum = 0
for idx, i in enumerate(a_list[:-1]):
  sum -= a_list[idx]
  output_sum += i*sum
  
print(output_sum%mod)

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

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

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

area = sum(l) * sum(l)

for i in l:
    area -= i*i

ans = area//2
ans = ans % mod
print(ans)

Solution (Python):
mod = 10**9 + 7
n = int(input())
a = list(map(int,input().split()))
prefix = list()
sum = 0
for i in a:
	sum += i
	prefix.append(sum)

res = 0
for i in range(0,n):
	t = (a[i] * (prefix[n - 1] - prefix[i])) % mod
	res = (t + res) % mod

print(res)

Solution (Python):
N = input()
a_list = [int(i) for i in input().split(' ')]
mod = 1000000007

sum_list = []
sum = 0
for i in a_list:
  sum += i
  sum_list.append(sum)

sum = 0
for idx, i in enumerate(a_list[:-1]):
  sum += i*(sum_list[-1]-sum_list[idx])
  
print(sum%mod)

Solution (Python):

MOD = 10 ** 9 + 7

N = int(input())

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





res = 0

cum_sum = sum(A)

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

res %= MOD

print(res)

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

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

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

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

print(ans)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
res = 0
mod = int(1e9 + 7)
for i in arr:
  s -= i
  res += i * s
  res %= mod
print(res)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
from itertools import accumulate


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, MOD=10**9+7):
    S = list(accumulate(A[::-1]))[::-1]
    ans = 0
    for i in range(N-1):
        ans += A[i] * S[i+1]
        ans %= MOD
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))