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):

import sys


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


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

    
    sum = 0
    for i in range(0, n):
        sum += aList[i]

    pro = 0
    for i in range(0, n):
        ai = aList[i]
        sum = sum - ai
        pro += sum * aList[i]

    out = resultSur97(pro)

    
    print("{}".format(out))

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


if __name__ == '__main__':
    main()

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

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

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

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

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

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
acc = [0]*(n+1)
for i in range(n-1,-1,-1):
    acc[i] = acc[i+1]+a[i]

x = 0
for i in range(n-1):
    
    x = (x+a[i]*acc[i+1])%R
print(x)

Solution (Python):

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

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

Solution (Python):
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)

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

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

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

a2 = s ** 2 - tr
a = a2 // 2
a %= 10 ** 9 + 7

print(a)

Solution (Python):
import numpy as np

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

modn = int(1e9 + 7)

ruiseki = sum(A)

ret = 0
for i in range(0, len(A)-1):
  ruiseki -= A[i]
  ret += A[i] * ruiseki

print(np.mod(ret, modn))

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

Solution (Python):






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

S = sum(A) % MOD

ans = 0


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

ans %= MOD

print(ans)

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

    s = sum(a)

    sm = 0

    for i in a:
        s -= i
        sm += i * s % mod

    print(sm % mod)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)



n = ii()
alist = lmis()

asum = sum(alist[1:n])

sum = 0
for i in range(n-1):
    sum += alist[i] * asum
    asum -= alist[i+1]

print(sum % 1000000007)

Solution (Python):
KK=10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
X=0
K=sum(A) %KK
for x in A:
    K-= x 
    X+=K*x
    X%=KK

print(X)

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


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

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
ruiseki=[0]
for i in range(1,n+1):
  ruiseki.append(ruiseki[i-1]+a[i-1])

ruiseki=ruiseki[1:]
mod=10**9+7
ma=max(ruiseki)
ans=0
for i in range(len(a)):
  ans+=((ma-ruiseki[i])*a[i])%mod
print(ans%mod)

Solution (Python):
import sys,itertools,collections,bisect
from collections import deque,Counter,defaultdict
from heapq import heappush,heappop,heapify
read=sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=(cum[i]+A[i])%MOD

ans=0
for i in range(N):
    res=(cum[N]-cum[i+1]+MOD)%MOD*A[i]%MOD
    ans=(ans+res)%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 x in A:
    S -= x  
    S %= MOD  
    ans += S * x
    ans %= MOD

ans %= MOD  
print(ans)

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

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

Solution (Python):




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

j_sum = 0
for j in range(N):
        j_sum = j_sum + A_input[j]


sum = 0
for i in range(N - 1 ):
        j_sum = j_sum - A_input[i]
        sum = sum +  A_input[i] * j_sum

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

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

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

Solution (Python):
import sys












stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    
    A = list(map(int, stdin.readline().rstrip().split()))
    
    
    
    
    S = [0]
    for i in range(n):
        S.append(S[i]+A[i])
    ans = 0
    for i in range(n-1):
        ans += (( A[i] * (S[-1] - S[i+1])) % MOD)
    print(ans%MOD)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys

N = int(sys.stdin.readline().strip())
vs = [int(a) for a in sys.stdin.readline().strip().split(" ")]

M = 1000000000 + 7

ret = 0
sum = 0
for j in range(1, N):
    sum += vs[j - 1]
    ret += (vs[j] * sum) % M
    ret = ret % M
print(ret)

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

P = sum(A)**2
Q = 0
for i in range (0, N):
    Q+=(A[i])**2

print(((P-Q)//2)%(10**9+7))

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

P = sum(A)**2
Q = 0
for i in range (0, N):
    Q+=(A[i])**2

print(((P-Q)//2)%(10**9+7))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = 1000000007
print(((sum(a)**2 - sum(map(lambda x: x**2, a))) // 2) % m)

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

mod = 10**9 + 7

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

print(ans%mod)

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

Solution (Python):
N,*A = map(int, open(0).read().split())
s = 0
m = 1000000007
for x in A:
    s = (s+x) % m
ans = 0
for x in A:
    s = (s-x) % m
    ans = (ans+x*s) % m
print(ans)

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

S = sum(a)
S2 = 0

for i in a:
    S2 += i * i

print((S*S - S2)//2 % inf)

Solution (Python):


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

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

main()

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
A = readInts()
cum = list(accumulate(A))
ans = 0
for i in range(n-1):
    ans += A[i] * (cum[n-1]-cum[i])
    ans%=mod
print(ans%mod)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.reverse()
S=sum(A)-A[0]
ans=0
for i in range(len(A)-1):
    ans+=A[i]*S
    S-=A[i+1]
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):
    S -= A[i]
    ans += A[i] * S
    

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

print(ans)

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

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

print(int(ans))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
s = 0
res = 0
m = 10**9+7
for ai in a:
  res += (s * ai) % m
  s += ai

print(res % m)

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

N = int(input())
A = np.array(list(map(int, input().split())))
A = A % MOD

AS = []
s = 0
for a in range(len(A)):
  s = (s + A[a]) % MOD
  AS.append(s)
AS = np.array(AS)

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

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

M = 10 ** 9 + 7
T = sum(map(lambda x: x**2, A))
print (((sum(A)**2-T)//2)%M)

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

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

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

summ=0

for i in l:
	summ+=i

ans=0
for i in l:
	summ-=i
	ans+=i*summ

print(ans%1000000007)

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

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

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

ans = 0

for i in range(N):
    sumA -= A[i]
    ans += A[i] * sumA
    ans %= a
    
print(ans)

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

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

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

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

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

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

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


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

Solution (Python):
import itertools


def main():
    count = 0
    MOD = 10**9+7
    n = int(input())
    a = list(map(int, input().split()))
    s = [0]
    for i in range(n-1):
        s.append((s[i]+a[i]) % MOD)
    for ai, si in zip(a, s):
        count += (ai*si) % MOD
    return count % MOD


if __name__ == "__main__":
    print(main())

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

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

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

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

Solution (Python):
"""C."""

import sys

input = sys.stdin.readline  

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

MOD_VALUE = 10**9 + 7
result = 0

a_sum = sum(a)

for v in a:
    result += v * (a_sum - v)
    a_sum -= v

if result < MOD_VALUE:
    print(result)
else:
    print(result % MOD_VALUE)

Solution (Python):
"""C."""

import sys

input = sys.stdin.readline  

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

MOD_VALUE = 10**9 + 7
result = 0

a_sum = sum(a)

for i, v in enumerate(a):
    result += v * (a_sum - v)
    a_sum -= v

if result < MOD_VALUE:
    print(result)
else:
    print(result % MOD_VALUE)

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

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

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












l = len(ai)

integ = [ai[0]] * len(ai)
for i in range(1, len(ai)):
    integ[i] = integ[i-1] + ai[i]

s = 0
for j in range(l):
    this_s = integ[-1] - integ[j]
    s += ai[j] * this_s

ans = s % (1000000000 + 7)

print(ans)

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

for ai in al:
    ans -= ai**2

print((ans//2)%mod)

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

S=sum(A)
a=0
for x in A:
  S-=x
  a+=S*x
    
MOD=10**9+7
print(int(a%MOD))

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

sum_list = sum(A)
sum_of_product = 0

for i in A:
    sum_list -= i
    sum_of_product = ((sum_list * i) % (10 ** 9 + 7) + sum_of_product) % (10 ** 9 + 7)

print(sum_of_product)

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

s = sum(a)
ans = 0

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

print(ans)

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

Solution (Python):
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7


n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
sum=sum*sum

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

ans=(sum-s)//2
ans%=J
print(ans)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

mod = 10**9 + 7

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    prefix = [a[0]]
    for i in range(1,n):
        prefix.append(prefix[i-1] + a[i])
    ans = 0
    for i in range(n-1):
        d = (a[i]*(prefix[-1] - prefix[i]))%mod
        ans = ans + d
        ans = ans%mod
    print(ans)

Solution (Python):

mod10_9p7 = 10**9 + 7

def main() :

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

    sop = [0] * (n-1)
    sop[0] = a_list[0]

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

    

    res = 0
    
    for i in range(n-1) :
        res += (a_list[i+1] * sop[i]) % mod10_9p7
        res = res % mod10_9p7
    
    print(res)
        

main()

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

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

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

Solution (Python):
num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
temp_sum = 0
for j in range(num):
	temp_sum += num_list[j]

for i in range(num):
	num_a = num_list[i]
	temp_sum -= num_a
	sigma += num_a * temp_sum


sigma %= law
print(sigma)

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

sq = 0
for i in range(n):
  sq += L[i]**2

tmp = (pow(sum(L),2) - sq) // 2
print(tmp % (pow(10,9)+7))

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

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

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

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

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

Solution (Python):
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  
    to_index = lambda x: int(x) - 1  
    print_list_in_2D = lambda x: print(*x, sep="\n")  

    
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

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

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

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

    
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    A = LII_split()

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

        
        
        
        if s > 10 ** 9 + 7:
            s %= 10 ** 9 + 7

    print(s)
    
resolve()

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

partial_sum = 0
sum_ = 0
for i in range(1, N):
  partial_sum += a_list[i-1]
  sum_ += a_list[i] * partial_sum
  
print(sum_ % (10 ** 9 + 7))

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

ans = 0
cumsum = 0

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

print(ans)

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

sumA = sum(A)
sumB = 0
sumC = sumA

for i in range(n):
    sumC = sumC- A[i]
    sumB += A[i] * sumC

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

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

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

      

print(sum%1000000007)

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

mod = 10**9 + 7
total =sum(an)
ans = 0
z = an[0]

for x in range(n-1):
  nokori = total-z
  ans += an[x] * nokori % mod
  z += an[x+1]

    
ans = ans % mod    
print(ans)

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


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


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

print(ans % mod)

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

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)

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

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

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

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

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

ans = 0
for i in A:
  s -= i
  ans += i * s

  
print(ans % MOD)

Solution (Python):


n = int(input())

arr = [int(i) for i in input().split(' ')]

parr = [0]*n

parr[n-1] = arr[n-1]

ans = 0
mod = int(10**9+7)

for j in range(n-2, -1, -1):
    parr[j] = arr[j] + parr[j+1]

    ans += arr[j] * parr[j+1]
    ans = ans % mod

print(ans)

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

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

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

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

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

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


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

Solution (Python):
N=int(input())
K=[int(n) for n in input().split()]
S=sum(K)
total=0
for i in range(N):
  S-=K[i]
  total+=K[i]*S
print(total %(10**9+7))

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

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

s = 0
r = [0] * N
r[0] = a[0]

for i in range(1, N):
    r[i] = r[i-1] + a[i]

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

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

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

zt=sum(A)**2
for _ in A:
  zt -= _**2
  
zt=(zt//2)%ao
print(zt)

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

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

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

print(ans)

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

total = sum(numbers)

m = 10 ** 9 + 7
result = 0
for number in numbers[:-1]:
  total -= number
  result += (total * number)
  result %= m
 
print(result)

Solution (Python):
import sys
from itertools import combinations
input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[0] = a[0]


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

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

print(ans)

Solution (Python):

from itertools import accumulate


def main():
    N, *A = map(int, open(0).read().split())
    rev_cumsum = list(accumulate(reversed(A[1:])))[::-1]
    MOD = 10 ** 9 + 7
    res = sum(a * c for a, c in zip(A[:-1], rev_cumsum)) % MOD
    print(res)


if __name__ == "__main__":
    main()

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

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

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

y = 0
for i in range(n):
    y += a[i]
    y = y % (2 * p)
x = (y ** 2) % (2 * p)

w = 0
for i in range(n):
    w += ((a[i] ** 2) % (2 * p))
    w = w % (2 * p)

z = ((x - w) / 2) % p
print(int(z))

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

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

sum_num = 0
sum_temp = sum(int_list[1:])

for i in range(N-1):
  sum_num += int_list[i] * sum_temp
  sum_temp -= int_list[i+1]
    
print(sum_num % (10 ** 9 + 7))

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

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

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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a)

ans %= 1000000007

print(int(ans))

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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a) % 1000000007

ans %= 1000000007
print(int(ans))

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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a) % mod

ans %= mod
print(int(ans))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
b = []
for i in range(n):
  b.append(a[i])
i = n-2
while i >= 0:
  b[i] += b[i+1]
  b[i] %= mod
  i -= 1


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

Solution (Python):
def main():
    import sys
    readline = sys.stdin.readline

    mod = 10**9 + 7

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

    sumA = sum(A) % mod
    ans = 0

    for i in A:
        sumA -= i
        ans += i * sumA
        ans %= mod

    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

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

sum_ans = sum(Ai)
ans = 0
mod = 1000000007

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

print(ans)

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

s = sum(a)
aa = [a[i]*a[i] for i in range(n)]
s2 = sum(aa)

print((s**2 - s2) //2%(10**9+7))

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

ans = 0
mod = int(1e9 + 7)
s = sum(A) % mod

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

print(int(ans))

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

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

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

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

N=int(input())
A=list(map(int,input().split()))
B=[0]
for x in A:
  B.append(B[-1]+x)

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

print(ans)

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

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
b=[0]
for i in range(n):
  b.append(b[i]+a[i])
c=0
for j in range(n-1):
  c+=a[j]*(b[n]-b[j+1])
  while c//(10**9+7)>0:
    c%=10**9+7
print(c)

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

modS = [0]
for i in A:
    modS.append((modS[-1] + i) % MOD)

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

print(ans)

Solution (Python):

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

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

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)

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

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

ans = ans%m

print(ans)

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

Solution (Python):
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N=II()
A=LI()

SA=sum(A)

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

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

Solution (Python):
times = int(input())
numbers = list(map(int, input().split()))
result = 0
sum_numbers = sum(numbers)
calc = []

for i in range(times - 1):
  sum_numbers -= numbers[i]
  calc.append(sum_numbers)

for i in range(times - 1):
  calc[i] *= numbers[i]
  
print(sum(calc) % (10 ** 9 + 7))

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

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

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

B = []

B_val = 0

ans = 0

for i in A[::-1]:
    B.append(B_val)
    B_val += i

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

print(ans % (1000000000 + 7 ) )

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

MOD = 10 ** 9 + 7

ans = 0
s = sum(A)
for a in A:
    s -= a
    ans += s * a
    ans %= MOD

print(ans)

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

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