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 copy import copy

N = int(input())
A = list(map(int, input().split()))
S,r,m = [0]*N,0,1000000007

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

for a,s in zip(A,S):
    r += (a*s)%m
    r %= m

print(r)

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

tot = sum(A)
ans = 0
for a in A:
  ans += (tot - a) * a
print(ans//2%1000000007)

Solution (Python):
n=int(input())
L=[int(x) for x in input().split()]
sum=0
product=0
mod=1000000007
for i in range(n):
    sum+=L[i]%mod
for i in range(n-1):
    sum-=(L[i]%mod)
    product+=sum*(L[i]%mod)
print(product%mod)

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

mod = 10**9+7
AA = sum(A)
ans = (AA%mod)**2
ans %= mod
for a in A:
    ans -= a**2
    ans %= mod
ans %= mod
print(ans*pow(2,mod-2,mod)%mod)

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

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

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

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

print(ans % m)

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

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

c=0
for j in range(n-1):
  c+=a[j]*(b[n-1]-b[j])
  
print(c%(10**9+7))

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

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

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

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

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
    s %= mod
    ans += i * s
    ans %= mod

print(ans)

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

Solution (Python):
n = int(input())
mod = 10**9+ 7
a = list(map(int,input().split()))
ans = (sum(a)%mod)**2 - sum([x**2%mod for x in a])
ans *= 5*10**8+4
ans %= mod
print(ans)

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



cumsum=[0]
def my_cumsum(alst):
  for i in range(len(alst)):
    cumsum.append(cumsum[i]+alst[i])
  return cumsum

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




s=my_cumsum(alst)

sum=0

for i in range(len(alst)-1):
  sum+=alst[i]*(s[len(s)-1]-s[i+1])

print(sum%MOD)

Solution (Python):
MOD = 10**9 + 7
def solve(n, a):
    t = sum(a)
    return sum((t-x)*x for x in a) // 2 % MOD

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

Solution (Python):
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

mod = 10 ** 9 + 7
print(int(ret//2) % mod)

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

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

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


    print(S%MOD)



from itertools import accumulate

m = 10**9 + 7

N,*A = map(int,open(0).read().split())

result = 0

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




for i in range (N-1):
    result += A[i]*(b[N-1]-b[i])
    result %= m
print(result)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
S = 0
S2 = 0
MOD = 1000000007
for i in range(N):
  S += A[i]
  S2 += A[i]*A[i]
print((S*S-S2)//2%MOD)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
S = [0]*N
S[N-1] = A[N-1]
for i in range(N-2,0,-1):
    S[i] = int((S[i+1] + A[i])%mod)

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

sum = int(sum%mod)    
print(sum)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
S = 0
for i in range(N):
    S += A[i]

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

sum = int(sum%mod)    
print(sum)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
inner_sum, total = 0, 0
for i in range(N):
    inner_sum += A[i]

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

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

X = 0
Y = 0
for a in A:
    X += a
    Y += a * a
X = (X * X) % mod
Y = Y % mod
Z = (X - Y + mod) % mod
ans = 0
if Z % 2 == 0:
    ans = Z / 2
else:
    ans = (Z + mod) / 2
print(int(ans))

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
S=0
M=0
for i in A:
    S+=i
for i in A:
    S-=i
    M+=(S*i)%mod
print(M%mod)

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

for i in a:
    sum_a -= i
    ans += i * sum_a
    ans %= 10**9 + 7
    
print(ans)

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

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

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

print(ans%mod)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
p = 10**9+7
sumA = 0
sumsq = 0
for i in range(len(A)):
  a = A[i]
  sumA += a
  sumA = sumA%p
  sumsq += pow(a, 2, p)
  sumsq = sumsq%p
sqsum = pow(sumA, 2, p)
if sqsum < sumsq:
  sqsum += p
if (sqsum - sumsq)%2 != 0:
  sqsum += p
ans = (sqsum - sumsq)//2
print(ans)

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

print((((sum(A)**2) - sum(map(lambda x:x*x, A))) // 2) % M)

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

mod = 1000000007
s = 0
for i in range(n):
  s += a[i]
  s %= mod

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

Solution (Python):
import numpy as np
MOD = 10 ** 9 + 7

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







s=[0]
for i in range(len(alst)):
  s.append(s[i]+alst[i])

sum=0

for i in range(len(alst)-1):
  sum+=alst[i]*(s[len(s)-1]-s[i+1])

print(sum%MOD)

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

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

mo=10**9+7
an=0
wk=0
ru=[]
for i in a:
    wk+= i
    ru.append(wk%mo)
for i in range(n-1):
    an+=a[i]*(ru[n-1]-ru[i])
    an%=mo

print(an)

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

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







s=[0]
for i in range(len(alst)):
  s.append(s[i]+alst[i])

sum=0

for i in range(len(alst)-1):
  sum+=alst[i]*(s[len(s)-1]-s[i+1])

print(sum%MOD)

Solution (Python):

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

MOD = 10 ** 9 + 7

sum = sum(a) % MOD
ans = 0

for i in range(len(a)):
    sum -= a[i]
    sum %= MOD
    ans += a[i] * sum
    ans %= MOD

print(ans)

Solution (Python):
MOD = int(1e9+7)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    sm = 0
    for a in A:
        sm = (sm + a) % MOD
    ans = 0
    for a in A:
        ans += ((sm-a) % MOD)*a
        ans %= MOD
    if ans % 2 == 0:
        ans //= 2
    else:
        ans = (ans + MOD) // 2
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
n,*a=map(int,open(0).read().split())

b=sum(map(lambda x:x*x,a))
mod=10**9+7
ans=(sum(a)**2-b)//2

print(ans%mod)

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

s=0
S=[]
for a in A:
    s += a
    s %= MOD 
    S.append(s)    

ans=0
for i in range(n-1):
    ans += S[i]*A[i+1]
    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 a in A:
    ans += a*(s-a)
print((ans//2)%mod)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()
a = readints()

mod = 10**9+7
s = sum(a)
ans = 0

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

print(ans)

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

res = sum(i for i in a)

ans = 0
for i in a:
    res -= i
    ans += i * res

print(ans % 1000000007)

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

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

print(ans)

Solution (Python):
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))
n = Ii()
a = Li()
sa = 0
ans = 0
mod = 10**9+7
for i in range(n-1):
  sa += a[i]
  ans += sa*a[i+1]
  ans %= mod
  
print(ans)

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


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


AA = []
for j in range(N):
	AA.append(A[j]*(SumA[N]-SumA[j+1]))


ans = sum(AA)%1000000007
print(ans)

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

s=sum(A)

ans=0
for a in A:
    ans+=a*(s-a)
print((ans//2)%mod)

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

from itertools import combinations

mod = 1000000007  

s = 0
ans = 0
for n in A:
    s += n
    s %= mod

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

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = 0
total = sum(A[1:])

for i in range(n-1):
    ans += A[i]*total
    total -= A[i+1]
    ans %= 1000000007

print(ans)

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

Solution (Python):




n = int(input())

zzz = list(map(int, input().split()))
b=sum(zzz)**2
a=0
for i in range(n):
  
  x=zzz[i]**2
  
  a +=x







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

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

mod = 1000000007

ans = 0
tmp1, tmp2 = 0, 0

for m in A:
  tmp1 = (tmp1+m) %mod
  tmp2 = (tmp2+m*m%mod)%mod
  
ans = ((tmp1*tmp1)%mod-tmp2)%mod

if ans%2 ==0:
  ans = ans/2
else:
  ans =(ans+mod)/2

print(int(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 += a[i]*s % mod
  ans = ans % mod

print(ans % mod)

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

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    MOD = 10 ** 9 + 7
    
    sum_a = sum(A)
    sum_squares = sum([a * a for a in A])
    
    ans = (sum_a ** 2 - sum_squares) // 2
    ans %= MOD

    print(ans)
    
    
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = [*map(int, input().split())]
s = sum(A)
s *= s
for a in A: s -= a * a
s //= 2
print(s % (10**9 + 7))

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    ans = 0
    s = list(accumulate(a[::-1]))[::-1][1:]
    for i in range(n-1):
        ans += a[i]*s[i]%mod
        ans %= mod
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College

'''
import sys
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007

inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]



def solve():
    
    
    
    
    
    
    
    n = ii()
    a = li()
    suff = [0]*n
    for i in range(n-2,-1,-1):
        suff[i] = suff[i+1]
        suff[i] += a[i+1]
        suff[i] %= mod
    
    ans = 0
    for i in range(n):
        x = a[i]*suff[i]
        x %= mod
        ans += x
        ans %= mod
    print(ans)
    
        
    
    
if __name__ =="__main__":
    
    solve()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = []
su = 0

la = len(a)
ele = a[la - 1]

for i in range(1, len(a) - 1):
    ele = ele + a[la - i - 1]
    b.append(ele)

lb = len(b)

for j in range(len(a) - 2):
    su = su + a[j] * b[lb - j - 1]

su = su + a[len(a) - 1] * a[len(a) - 2]

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

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

ans = sum(a)**2
for i in range(n):
    ans -= a[i]*a[i]
ans //= 2
ans %= MOD
print(ans)

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

su = sum(a)
sus = 0

for i in a:
    su = su - i
    sus = sus + i * su

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

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

for i in range(N):
  ak += A[i]
  ak_2 += A[i] ** 2
s = int(((ak ** 2) - ak_2) // 2)
print(s % mod)

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

tot = 0
s_tot=0

def modpow( a , n , m):
    ans=1
    n_bit = bin(n)[2:]
    l=len(n_bit)
    for i in list(range(l))[::-1]:
        if n_bit[i]=="1":
            ans = (ans * a) % m
        
        a=(a*a) %m
        
    return ans
inv_2 = modpow( 2 , M-2 , M)
for i in range(n):
    y=X[i]
    
    tot = (tot + y) % M
    s_tot = (s_tot + y**2%M ) % M

ans= ((tot ** 2 - s_tot )* inv_2 ) % M
print(ans)

Solution (Python):
MOD = int(1e9+7)


def main():
    n = int(input())    
    A = list(map(int,input().split()))
    sum_a = 0
    for a in A:
        sum_a = (sum_a + a) % MOD
        
    ans = 0
    for a in A:
        sum_a = (sum_a - a) % MOD
        ans = (ans + ((a*sum_a) % MOD)) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

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


a.reverse()
b = [0]*n
b[0] = a[0]
for i in range(1, n):
    b[i] = b[i-1]+a[i]
a.reverse()
b.reverse()

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

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

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

A_sum = sum(A)

value = 0
ans = 0

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

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

print(ans)

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

Solution (Python):




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

    s = sum(A)
    ans = 0
    mod = 10**9 + 7
    for i in A:
        ans = (ans + i * (s - i))
    print((ans // 2) % mod)


if __name__ == "__main__":
    main()

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

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

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

    return answer % MOD

print(solve(N, A))

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

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)  
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))

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

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

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

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

SU = [0] * (len(A)+1)

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

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

print(ans%MOD)

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

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

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

s = sum(a[1:])
ans = 0

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

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


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

sum_ = sum(A)
ans = 0

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

print(ans)

Solution (Python):
from itertools import accumulate

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


a_acm = list(accumulate(a[::-1]))

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

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

sum = 0
for i in range(0,n):
    sum += li[i]
    sum %= mod

ans = 0
for i in range(0,n):
    sum -= li[i]
    if sum < 0:
        sum += mod
    ans += li[i] * sum
    ans %= mod
print(ans)

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

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

MOD = 10**9 + 7

sum_a = sum(A)
sum_squares = sum([a*a for a in A])

ans = (sum_a**2 - sum_squares)//2
ans %= MOD

print(ans)

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

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

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

Solution (Python):
n=int(input())
c = list(map(int, input().rstrip().split()))
ans=0
b=10**9+7
sum1=0
for i in range(n):
    ans=(ans+c[i]*sum1)%b
    sum1=(sum1+c[i])%b

    
    
    
        
print(ans)

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

ans= 0
total = sum(s)

for i in range(len(s)-1):
  total -= s[i]
  ans += total * s[i]

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

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

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

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

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

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

print(ans)

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

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

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

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

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

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

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

S1 = sum(A)**2
S2 = sum(a*a for a in A)

print((S1 - S2)//2 %mod)

Solution (Python):




import numpy as np

N = int(input())



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










sum_A = sum(A)
A = np.array(A)

cum_A = np.cumsum(A)



























tot = 0
for i in range(N):
    tot += int(A[i]) * (sum_A - int(cum_A[i]))
        
print(tot % 1000000007)

Solution (Python):

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


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

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


_sum = _sum % (1000000000+7)
  
print(_sum)

Solution (Python):






N = int(input())



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





































sum_A = sum(A)

tot = 0
for i in range(N):
    sum_A -= A[i]
    tot += A[i] * sum_A
        
print(tot % 1000000007)

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

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

mod = 10**9+7
cuml = [al[0]]
for i in range(n-2):
    cuml.append((cuml[i]+al[i+1]) % mod)
ans = 0
for i in range(1, n):
    ans = (ans+cuml[i-1]*al[i]) % mod
print(ans)

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

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

sumA = sum(A)

ans = 0
for a in A:
  sumA -= a
  ans += sumA * a

print(ans % 1000000007)

Solution (Python):
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
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):
  s-=a[i]
  ans+=a[i]*s
  if ans>(10**9+7):
    ans=ans%(10**9+7)
print(ans)

Solution (Python):
N = int(input())
A = [int(v) for v in input().split()]
MOD = int(1e9 + 7)

S = sum(A)
SQ = S * S
IS = sum(a*a for a in A)

print(((SQ - IS) // 2) % 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 %(int(1e9 + 7))

print(ans)

Solution (Python):
from itertools import accumulate

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

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

print(ans)

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

kake=0
ans=0
sum=0
anskai=0
for i in range(N):
    kake=s[N-1]-s[i]
    ans=a[i]*kake
    sum+=ans
anskai=sum%(10**9+7)
print(anskai)

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

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

s=[0]
for i in range(len(alst)):
  s.append(s[i]+alst[i])

sum=0

for i in range(len(alst)-1):
  sum+=alst[i]*(s[len(s)-1]-s[i+1])

print(sum%MOD)

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

max = (10 ** 9) + 7


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


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

sum = ((line*line) - rem) // 2

ans = sum % max

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
S = sum(A)
S2 = sum(map(lambda x: x*x,A))
ans = (S*S - S2)// 2 % mod
print(ans)

Solution (Python):

import itertools
n = int(input())
a = list(map(int, input().split()))
cum = [0] + list(itertools.accumulate(a))

ans = 0
mod = 10**9 + 7

for i in range(n):
    ans += a[i] * cum[i]
    

print(ans % mod)

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

mod = 1000000007


ans = 0
n = A[0]
for a in A[1:]:
    ans += a * n
    n += a

print(ans%mod)

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

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

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

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

Solution (Python):
import math
from decimal import *
import random

n = int(input())
arr = list(map(int, input().split()))
cnt = 0
pref  = [0 for i in range(n)]
for i in range(n):
    cnt+=arr[i]
    pref[i] = cnt
ans = 0
for i in range(n):
    ans= (ans+(pref[n-1]-pref[i])*arr[i])%(int(1e9)+7)
print(ans)

Solution (Python):
N = int(input())
A_list = [int(_) for _ in input().split()]

c = 10**9+7


def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


inv = modinv(2, c)

sum_of_a = sum(A_list) % c
sum_of_sq_a = sum([i**2 for i in A_list]) % c

ans = (sum_of_a**2 % c - sum_of_sq_a)*inv %c

print(ans)

Solution (Python):
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 += a[i]*total
    ans %= mod
print(ans)

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

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

print((ans//2)%mod)

Solution (Python):
mod = 10**9 + 7
N = int(input())
array = [int(i) for i in input().split()]
array_2 = [0]

for a in array:
    array_2.append(array_2[-1]+a)
    
output = 0
for i in range(len(array)-1):
    output += array[i] * (array_2[-1] - array_2[i+1])
    
print(output%mod)

Solution (Python):
N = int(input())
A = [int(v) for v in input().split()]
mod = 1000000007
cusum = [0]
for i in range(N):
    cusum.append(cusum[i] + A[i])

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

Solution (Python):
import itertools

N = int(input())
A = list(int(x) for x in input().split())

mod = 10**9+7

sum_ = 0
ans = 0

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

print(ans)

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

mod = 10**9 + 7

cusum = [0]
for i in range(n):
    cusum.append(cusum[i]+A[i])

totalSum = 0
for i in range(n-1):
    sum = (cusum[n] - cusum[i + 1]) % mod
    totalSum += sum * A[i]
    totalSum %= mod

print(totalSum)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()

sss = list(itertools.accumulate(A))
ss = sum(A)
s = 0
for i in range(len(A)-1):
    s = (s + ((ss-sss[i]) * A[i])) % mod

print(s)

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