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 math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate

int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

def findProductSum(A, n): 
    T = list(accumulate(A[::-1]))[::-1]
    
    Ans = 0
    for i in range(n-1):
        x = A[i]*T[i+1]
        x %= MOD
        Ans += x
        Ans%= MOD
    return Ans
    

N= int(input())
A  = alele()
print(int(findProductSum(A,N) % MOD))

Solution (Python):

from itertools import accumulate
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = (accumulate(reversed(a)))
    a_sum = list(reversed(list(a_sum)))
    sum = 0
    mod = 1000000007
    for i in range(n-1):
        sum += a[i]*a_sum[i+1]
    print(sum%mod)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

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

mod=10**9+7

csum=[0]
for i in a:
    csum.append((csum[-1]+i)%mod)

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

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
mod=pow(10,9)+7
numbers=[]
num=0
for a in A:
    num+=a
    numbers.append(num)
ans=0
last=numbers[-1]
for n in range(N-1):
    number=numbers[n+1]-numbers[n]
    ans+=(number*(last-numbers[n+1]))
ans+=(A[0]*(last-A[0]))
ans=ans%mod
print(ans)

Solution (Python):
n=int(input())
L=list(map(int,input().split()))
cnt=0
for i in range(n):
	cnt+=L[i]**2

ans=(sum(L)**2-cnt)//2
mod=pow(10,9)+7

print(ans%mod)

Solution (Python):
from itertools import accumulate


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

acc = list(accumulate(A, initial=0))
ans = 0
for i in range(1, N):
    ans += A[i - 1] * (acc[N] - acc[i])
    ans %= MOD
print(ans)

Solution (Python):
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=read()
a=list(reads())
num=0
l=len(a)
ls=[]
k=0
for i in range(l-1,0,-1):
    k+=a[i]
    ls.append(k)
for i in range(l-1):
    num+=a[i]*ls[-i-1]
num%=10**9+7
print(num)

Solution (Python):


import functools


M = 10 ** 9 + 7


def sum_mod(xs):
    return functools.reduce(lambda x, y: (x + y) % M, xs) % M


def compute(bs):
    term1 = sum_mod(bs) * sum_mod(bs) % M
    term2 = sum_mod(b * b for b in bs)
    double_res = (term1 - term2) % M
    inv2 = pow(2, M - 2, M)
    res = double_res * inv2 % M
    return res


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    res = compute(bs)
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    mod = 10**9 + 7
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = list(it)

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

if __name__ == "__main__":
    resolve()

Solution (Python):






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





mod = 10**9+7
a_sum = sum(A)
a_sum_list = []
cnt = 0
for i,a in enumerate(A):
    a_sum_list += [a_sum-a-cnt]
    cnt += a
mylist = [a_sum_list[i]*a for i,a in enumerate(A)]
ans = sum(mylist)%mod
print(ans)

Solution (Python):
n=int(input())
lis=list(int(x) for x in input().split() )
ans=0
x=10**9+7
su=0
for i in range(len(lis)) :
    su=su+lis[i]
for i in lis :
    su=su-i
    ans=(ans+su*i)%x

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)
    ans %= 10**9+7

print(ans)

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

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


def main():
    SUM = []
    now = 0
    ans = 0
    for i in range(N):
        now += A[i]
        SUM.append(now)
    
    for i in range(N):
        ans += A[i] * (SUM[-1] - SUM[i])
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    S = sum(A)
    count = S
    ans = 0
    for i in A:
        count -= i
        ans += count*i
        if ans > 10**9+7:
            ans %= (10**9+7)
    print(ans)
resolve()

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

ans=0
inf=10**9+7
flag=True
total=0
for i in range(N):
    total+=A[i]
    total%=inf

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

Solution (Python):
def findProductSum(A, n):

    array_sum = 0
    for i in range(0, n, 1):
        array_sum = array_sum + A[i]

    array_sum_square = (array_sum * array_sum)

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

    return ((array_sum_square -
             individual_square_sum) // 2) % (10**9+7)
n=int(input())
a=list(map(int,input().split()))
print(findProductSum(a,n))

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

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

Solution (Python):

p = 10**9+7

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


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

Solution (Python):
N=input()
A=list(map(int, input().split()))
mod=10**9+7
g=sum(A)%mod
r=0
for i in A:
  r+=i**2
  r%=mod
ans=(g**2-r)*pow(2,-1,mod)
ans%=mod
print(ans)

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

data = input().split()

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

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

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

print(ans % 1000000007)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
base = 10 ** 9 + 7
X = 0
Y = 0
for i in A:
  X += i * i
  Y += i
  X %= base
  Y %= base
Y = (Y * Y) % base
ans_ = ( Y - X ) % base

m = pow(2, base-2, base)

print( (ans_ * m) % base )

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)

suma=0
for a in A:
    suma = (suma + a) % P
ans=0
for a in A:
    suma = (suma - a)%P
    ans = (ans + a * suma) % P
print(ans)

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

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_sum*(A[i])

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

Solution (Python):
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
mod=10**9+7
sum_a=sum(A)
ans=0
for i in range(N):
    sum_a=sum_a-A[i]
    ans+=sum_a*A[i]
    ans%=mod

print(ans)

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

mod = 10**9 + 7
ans = 0
A_sum = [0]

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

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

print(ans)

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

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sum1 = sum(a)
ans=0
for x in a:
	sum1-=x;
	ans+= (x*sum1)
	
print(ans%1000000007)

Solution (Python):





def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(map(int,input().split())))
    return np.array(x)

def str_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

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

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

def print_space(l):
    return print(" ".join([str(x) for x in l]))


import numpy as np
import collections as col


N = int(input())
A = int_list()

sumlist = []
sumlist.append(A[0])

for i in range(1,N):
    sumlist.append((sumlist[i-1]+A[i])%(10**9+7))

a = 0

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

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

Solution (Python):
a=int(input())
m_list=list(map(int,input().split()))
sum=sum(m_list)
count=0
for i in range(a) :
  count+=m_list[i]**2

answer=(sum**2-count)//2
print(answer%(10**9+7))

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

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

ans = 0

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

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

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

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

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

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

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

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

print(ans)

Solution (Python):
n = int(input())
a_array = map(int, input().split())
MOD = 10 ** 9 + 7
a_array = [a % MOD for a in a_array]
sum = 0
square_sum = 0
for i in range(n):
    sum += a_array[i]
    sum %= MOD
    square_sum += pow(a_array[i], 2, MOD)
    square_sum %= MOD

ans = pow(sum, 2, MOD) - square_sum
ans *= 500000004
ans %= MOD
print(ans)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
ra=A[::-1]
S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+ra[i]
M=10**9+7

S=S[::-1]
i=0
ans=0
while i<N:
    ans+=A[i]*S[i+1]
    ans%=M
    i+=1
print(ans)

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

sum1 = 0
sum2 = 0

for _ in a:
  sum1 += _
  sum2 += (_*_)
sum1 = (sum1 * sum1)
print(((sum1 - sum2)//2)%1000000007)

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

Solution (Python):
n= int(input().strip())
a= list(map(int, input().strip().split()))
x=0
A=0

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

Solution (Python):
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

MOD = 10**9 + 7
def main():
	n = int(input()); arr = read()
	pref = [i for i in arr]
	for i in range(1, n):pref[i] += pref[i-1]
	ans = 0
	for i in range(n):
		ans += (arr[i] * (pref[-1]-pref[i]))%MOD
		ans %= MOD
	print(ans)



if __name__ == "__main__":
	main()

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]



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

print(ans)

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

Solution (Python):

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

mod=10**9+7

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

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

print(ss%mod)

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

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

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

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

print((((s**2) - ss) // 2) % mod)

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

abc177c()

Solution (Python):
def findProductSum(A, n): 
      
    array_sum = sum(A)
    array_sum_square = array_sum ** 2
    
    individual_square_sum = 0
    for i in range(n): 
        individual_square_sum += A[i] * A[i] 
  
    return (array_sum_square - individual_square_sum) // 2

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

print(findProductSum(A, N)%(10**9+7))

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

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

MOD_BY = 10**9 + 7




right_sum = sum(A_list)%MOD_BY
ans = 0
for i in range(N-1):
    right_sum -= A_list[i]
    
    ans += A_list[i]*right_sum%MOD_BY
    
print(ans%MOD_BY)

Solution (Python):
import sys

mod = 10**9+7
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A = LI()
    A_sum = sum(A)
    ans = 0
    for i in range(n-1):
        A_sum -= A[i]
        ans += A[i]*A_sum
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

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

MOD = 1000000007

Alist = Alist[::-1]

mod = 0

ans = 0
for n in range(N-1):
    mod += (Alist[n]%MOD)
    mod = mod % MOD
    ans += (Alist[n+1] * mod)%MOD

print(ans%MOD)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    all_val = sum(A)
    A = A[::-1]

    sum_val = 0
    for i in range(len(A)):
        all_val -= A[i]
        sum_val += all_val * A[i] % (10**9 + 7)
    return sum_val % (10**9 + 7)

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

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

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

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

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

Solution (Python):

import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7

N=int(input())
A=list(map(int,input().split()))
Asum = sum(A)
Asum_list = []
for i in range(N):
    Asum -=A[i]
    Asum_list.append(Asum)
ans = 0
for a,b in zip(A,Asum_list):
    ans = (ans + a*b)%m
print(ans)

Solution (Python):

import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        ans += A[i]
        ans %= m
    ans = ans**2
    ans %= m
    for i in range(N):
        ans -= pow(A[i],2,m)
        ans %= m
    
    ans = ans * pow(2,m-2,m) % m
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A_List = [int(i) for i in input().split()]

Y = 0
M = 10**9+7
tempSum = sum(A_List)

for x in A_List:
    tempSum -= x
    Y += x * tempSum
    Y = Y%M
print(Y)

Solution (Python):


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

mod = int(1e9)+7

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

print(ans%mod)

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

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

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ss=s**2
c=0
for i in range(n):
    c+=(l[i]*l[i])
p=(ss-c)//2
print(p%1000000007)

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

p = int(1e9 + 7)

result = 0
total = 0
for i in range(N - 1, 0, -1):
    total = (total + A[i]) % p
    result = (result + A[i-1] * total) % p
print(result)

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

mod = 10 ** 9 + 7
sumnumber = sum(AList)

result = 0
for i in AList:
    result += (sumnumber - i) * i
    
    sumnumber -= i

print(result % mod)

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

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

print(ans)

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

A = np.array(A, np.int64)
a1 = A.sum() % M
a1_sq = a1**2 % M
a2 = (A**2 % M).sum() % M
diff = (a1_sq - a2) % M

if diff % 2 == 0:
    print(diff // 2)
else:
    res = (diff + M) // 2 % M
    print(res)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

suma = sum(a)
sumaa1 = (suma**2//2)%p

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

ans = (sumaa1-sumaa2)%p

print(ans)

Solution (Python):
from itertools import accumulate
n = int(input())
div = 10 ** 9 + 7
lst = list(map(int, input().split()))
ACC = list(accumulate(lst))
ACC.pop(n - 1)
res = 0
for i in range(n - 1):
  res += (lst[i + 1] * ACC[i])
  res %= div
print(res)

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

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

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

def egcd(a, b):
    lastremainder, remainder = abs(a), abs(b)
    x, lastx, y, lasty = 0, 1, 1, 0
    while remainder:
        lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
        x, lastx = lastx - quotient*x, x
        y, lasty = lasty - quotient*y, y
    return lastremainder, lastx * (-1 if a < 0 else 1), lasty * (-1 if b < 0 else 1)


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise ValueError('modinv for {} does not exist'.format(a))
    return x % m

n = int(input())
A = [int(i) for i in input().split()]
ans = sum(A)**2 % mod
for i in A:
    ans -= i**2
    ans %= mod
ans *= modinv(2, mod)
ans %= mod
print(ans)

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

print(com%mod)

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

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

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

print(ans % mod)

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

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

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    mod = 10 ** 9 + 7

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

    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
N = int(input())
A = list(map(int, input().split()))


q=deque(A)

ans=0
sums=sum(q)

for i in range(N-1):
    qwe=q.popleft()
    ans+=qwe *(sums-qwe)
    sums-=qwe
print(ans%(10**9+7))

Solution (Python):
MOD = pow(10, 9) + 7
waru2 = pow(2, MOD-2, MOD)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    taikaku = 0
    for i in range(N):
        taikaku += pow(A[i], 2)
        taikaku %= MOD
    zennbu = 0
    sumA = sum(A)
    for i in range(N):
        zennbu += A[i]*sumA
        zennbu %= MOD
    
    ans = ((zennbu - taikaku) * waru2) % MOD
    print(ans)

if __name__ == "__main__":
    main()

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

S = sum(A)
ans = 0

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

print(ans)

Solution (Python):
n = int(input())
elems = []
pref = []
raw = input().split(" ")
idx = 0
while(idx < n):
    elem = int(raw[idx]);
    elems.append(elem)
    if(idx == 0):
        pref.append(elems[idx])
    else:
        pref.append(pref[idx - 1] + elem)
    idx += 1

sum = 0
for idx in range(n):
    sum += elems[idx] * (pref[n - 1] - pref[idx])

print(sum%1000000007)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
from functools import reduce
S=reduce(lambda x,y:(x+y)%mod,A)
B=[]
for i in range(n):
    S=(S-A[i])%mod
    B.append(S)
N=0
for i in range(n):
    N=(N+A[i]*B[i])%mod
print(N)

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

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

for i in A:
    ruiseki.append(ruiseki[-1] + i)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6
mod = 10 ** 9 + 7 

from decimal import *



N = INT()
A = LIST()

A_acc = []
tmp = 0
for a in A:
	tmp += a
	tmp %= mod
	A_acc.append(tmp)

ans = 0
for i, a in enumerate(A):
	ans += a*(A_acc[-1]-A_acc[i])
	ans %= mod

print(ans)

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

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

dot = sum(A)**2 % MOD
diag = sum(a**2 % MOD for a in A)
answer =  (dot - diag) * pow(2, -1, MOD) % MOD

print(answer)

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

MOD = int(1e9) + 7

N = int(input())
A = list(map(int, input().split()))
S = sum(A) % MOD

ans = 0

for a in A:
    ans += a * (S - a + MOD) % MOD
    ans %= MOD
div2 = (MOD + 1) // 2
print(ans * div2 % MOD)

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

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ret = 0
    sum_list = [None] * n + [0]
    for i in range(n-1, -1, -1):
        sum_list[i] = sum_list[i+1] + a[i]
    for i in range(n):
        ret += a[i] * sum_list[i+1]
        ret %= 1000000007
    print(ret)

if __name__ == "__main__":
    main()

Solution (Python):
mod = 1000000007
n = int(input())
als = list(map(int, input().split()))

sumlist = [0 for _ in range(n)]
sumlist[0] = als[0]

for i in range(1, n-1):
    sumlist[i] = sumlist[i-1] + als[i]

ans = 0

for i in range(n-1):
    ans += als[n-1-i] * sumlist[n-2-i]
    ans = ans%mod

print(ans)

Solution (Python):

"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))

    A_square_list = [A**2 for A in A_lsit]

    sum_A = sum(A_lsit)
    sum_A_square = sum(A_square_list)

    print( ((sum_A**2 - sum_A_square)// 2) % 1000000007 )

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    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])
ans = 0
mod = 10**9+7
for i in range(1,n):
  ans += a[i]*A[i]%mod
print(ans%mod)

Solution (Python):
def solve() :
    n = int(input())
    a = list(map(int, input().split()))
    a2 = [i ** 2 for i in a]

    print(((sum(a)**2 - sum(a2))//2)%(10**9+7))

if __name__ == "__main__" :
    solve()

Solution (Python):
import sys

n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))

pref = [lst[0]]
for i in range(1, len(lst)):
    pref.append(pref[i-1]+lst[i])

ans = 0
for i in range(len(lst)):
    ans += lst[i] * (pref[-1] - pref[i])

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

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

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

ls = list(map(int,input().split()))
mod = 10**9+7
acc = [0]

for a in ls:
  acc.append(acc[-1]+a)
  
ans = 0

for i in range(len(ls)-1):
  ans += ls[-i-1]*acc[-i-2]
  ans %= mod


print(ans)

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

MOD=10**9+7

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

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

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

print((t)*pow(2,MOD-2,MOD)%MOD)

Solution (Python):
import itertools
n = int(input())
a = list(map(int,input().split()))
a_c = list(itertools.accumulate(a))
MOD = 10**9 + 7
cnt = 0

for i in range(n):
    temp = a[i] * (a_c[-1] - a_c[i])
    cnt += temp

print(cnt % MOD)

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

ans=sum(A)%(2*(10**9+7))
ans=ans**2%(2*(10**9+7))

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

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

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

mo = 10**9 + 7
ans = 0
su = li[0]
for i in range(1,len(li)):
    ans += li[i]*su
    su+=li[i]
print(ans % mo)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from itertools import accumulate as acc
MOD=10**9+7

def main():
    n = II()
    aa = MII()
    aa_cum = list(acc(aa))
    ans = 0
    for i in range(n):
        mul = aa_cum[-1] - aa_cum[i]
        ans += (aa[i]*mul)%MOD
    print(ans%MOD)


if __name__ == '__main__':
    main()

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

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

ans = 0
acc = [0] + list(accumulate(A))
for i, a in enumerate(A):
    ans += ((acc[-1] - acc[i + 1]) * a) % MOD
    ans %= MOD

print(ans % MOD)

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