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):
def inverse(a, mod):
    a %= mod 
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod 
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
s = sum(a)

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

Solution (Python):
import math
from fractions import Fraction as frac

MOD = 1000000007

def solve(case_no):
    n = int(input())
    a = list(map(int, input().split()))
    ps = [a[0]]
    for i in range(1, n):
        ps.append(ps[i - 1] + a[i])
    ans = 0
    for i in range(n - 2, -1, -1):
        ans += a[i + 1] * ps[i]
        ans %= MOD
    print(int(ans))

t = 1

for i in range(1, t + 1):
    solve(i)

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

mod = 10 ** 9 + 7

s = 0
ans = 0

for i in a:
    ans += s * i
    ans %= mod
    s += i
    s %= mod

print(ans)

Solution (Python):



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

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

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

A = np.array(read().split(), np.int64)[1:]

x = A.sum() % MOD
y = (A * A % MOD).sum() % MOD
x = (x * x - y) % MOD
if x & 1:
    x += MOD
print(x // 2)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = []
now = 0
for i in range(n)[::-1]:
    now += a[i]
    now %= mod
    b.append(now)
b = b[::-1]
res = 0
for i in range(n-1):
    res += a[i]*b[i+1]
    res %= mod
print(res)

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

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

if __name__ == "__main__":
    main()

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

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

print(ans)

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

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

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

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])
print(ans//2%(10**9+7))

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

mod = 10**9+7

S = 0
T = 0
for a in A:
    S = (S+a  )%mod
    T = (T+a*a)%mod

ans = (S*S-T)%mod
print(ans*pow(2, mod-2, mod)%mod)

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

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

Solution (Python):
from sys import stdin
input = stdin.readline
MOD = 10**9 + 7

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = A[0]
    ans = 0
    for i in range(1, N):
        ans += S * A[i]
        ans %= MOD
        S += A[i]
        S %= MOD
    print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
a = sum(A) ** 2 % mod
b = sum([a * a for a in A]) % mod
p = mod - 2
bin_p = []
while p:
  bin_p.append(p % 2)
  p >>= 1
ret = 1
for j in reversed(bin_p):
  ret = (ret * ret) % mod
  if j == 1:
    ret = (ret * 2) % mod
print((a - b) * ret % mod)

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

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

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

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

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

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
s = sum(lst)
cum = 0
total = 0
mod = 10**9+7
for i in range(n):
    cum += lst[i]

    total = (total + ( lst[i]*(s - cum) ) )%mod
print(total)

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

Solution (Python):
N=int(input());
X=list(map(int,input().split()))
s=0;t=0;
for i in range(N):
  s+=X[i];
  t+=X[i]*X[i];
print(((s*s-t)//2)%1000000007)

Solution (Python):
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
sumA = 0
for ai in A:
    sumA = (sumA + ai) % MOD
ans = 0
for ai in A:
    sumA = sumA - ai
    ans = (ans + sumA * ai) % MOD

print(ans)

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

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

INF=10**9+7

s=0
for i in a:
    s=(s+i)%INF

d=0
for i in a:
    d=(d+i**2)%INF

ans=(s**2-d)%INF

def modinv(a,m):
    b=m
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while not b==0:
        q=a//b
        (a,b)=(b,a%b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx%m
ans=(ans*modinv(2,INF))%INF

print(ans)

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


ans = 0
n = inp()
a = inpl()
tmp = a[0]
for i in range(1, n):
    ans += tmp * a[i] % mod
    ans %= mod
    tmp += a[i]
print(ans)

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

Solution (Python):
import sys

n=int(input())
pref=[0]
mod=10**9
mod+=7
a=[int(o) for o in input().split()]
ans=0
for i in a:
    pref.append(pref[-1]+i)
    ans+=((i*pref[-2])%mod)
    ans%=mod


print(ans%mod)

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

slist=[0]*N
sum_a=0
for i in reversed(range(N)):
  sum_a+=alist[i]
  slist[i]=sum_a  


answer=0
for i in range(N-1):
  answer+=alist[i]*slist[i+1]
  answer%=MOD
  
print(answer)

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

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

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

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

mod = 10**9+7
s = 0
nizyo = 0

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

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

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

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

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

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

print(((sum(a)**2 - sum([e**2 for e in a])) // 2) % (10**9 + 7))

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

mod = 10**9 + 7

summm = sum(nums) % mod
sum_square = sum([num ** 2 for num in nums]) % mod

ans = (summm ** 2 - sum_square) % mod
ans *= (mod + 1) // 2
ans %= mod
print(ans)

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

MOD = int(1e9 + 7)
res = 0
sum = 0

for n in v:
  res = (res + (n % MOD * sum) % MOD) % MOD
  sum = (sum + n) % MOD

print(res)

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

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

mod = 10 ** 9 + 7

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

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

Solution (Python):
import sys

def solve():
      input = sys.stdin.readline
      N = int(input())
      A = [int(a) for a in input().split()]
      sumA = 0
      mod = 7 + 10 ** 9
      for a in A:
            sumA += a
            sumA %= mod
      ans = 0
      for a in A:
            ans += ((sumA - a + mod) * a) % mod
            ans %= mod
      print((ans * pow(2, mod-2, mod)) % mod)

      return 0

if __name__ == "__main__":
      solve()

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

s = sum(a)

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

print(r)

Solution (Python):
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy


MOD = 10 ** 9 + 7



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

su = [0]*n
su[-1] = A[-1]
for i in reversed(range(n-1)):
    su[i] = (A[i]+su[i+1])%MOD

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

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

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

cum = [0]*n

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

ans = 0

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

print(ans)

Solution (Python):

import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

M = 10**9+7
n = inp()
x = ip()

sm = sum(x)
sq = sm*sm
ans = 0
for i in x: ans += i*i
ans = (sq-ans)//2
print(ans%M)

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

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
MOD=10**9+7
tmp1 = 0
tmp2 = 0
for a in A:
    tmp1 += a
    tmp2 += (a**2)

ans = (tmp1**2 - tmp2)//2
print(ans%MOD)

Solution (Python):

n, *a = map(int, open(0).read().split())
s = ans = 0
MOD = 10**9+7
for b, c in zip(a, a[1:]):
    s = (s + (b % MOD)) % MOD
    ans = (ans + s * (c % MOD) % MOD) % MOD
print(ans)

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

if __name__=="__main__":
    main()

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

ans = 0
for i in range(n):
  ans = (ans + ((a[i] % p) * suma[i])%p)%p
print(ans)

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

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


def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    ans = 0
    for i in range(N-1):
        ans += A[i] * (S[N] - S[i+1])
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

sm=sum(l)
ans=0

for i in l:
  sm-=i
  ans+=i*sm
  ans%=1000000007
print(ans)

Solution (Python):
def read_ints():
    return map(int, input().split(' '))


mod = int(1e9 + 7)


def fexp(x, y):
    ret = 1
    while y > 0:
        if y % 2 == 1:
            ret = ret * x % mod
        x = x * x % mod
        y = y // 2
    return ret


input()
a = list(read_ints())
s = sum(a)
ans = 0
for i in a:
    ans = (ans + i * (s - i)) % mod
print(ans * fexp(2, mod - 2) % mod)

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

a1 = sum(a)**2 
a2 = 0
for i in range(len(a)):
    a2 = (a2 + (a[i]**2)) 

ans = ((a1 - a2) // 2) % 1000000007
print(ans)

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

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

sum1 = 0
sum2 = 0
for a in A:
  sum1 = (sum1 + a)
  sum2 = (sum2 + a**2)

answer = ((sum1**2 - sum2) // 2) % mod
print(answer)

Solution (Python):
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
from collections import deque
from bisect import *
N=int(input())
A=list(map(int,input().split()))
cuml=[0]*N
p=10**9+7
for i in range(N-1):
    cuml[i+1]=(cuml[i]+A[i])%p

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

Solution (Python):
N = input()
arr = list(map(int,input().split(" ")))
MOD = int(1e9+7)
sum_arr = sum(arr) % MOD
res = 0
for a in arr:
    sum_arr = (sum_arr-a)%MOD
    res = (res+ sum_arr*a)%MOD
print(res)

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

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

N= int(input().rstrip('\n'))
As = [int(x) for x in input().rstrip('\n').split()]
s = sum(As)**2
b = sum(x**2 for x in As)
print(((s-b)//2)%1000000007)

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

mod = 10 ** 9 + 7
N = 1000


inv_t = [0]+[1]
for i in range(2, N):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]


kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
	kai.append(kai[-1] * i % mod)
	rev_kai.append(rev_kai[-1] * inv_t[i] % mod)


def cmb(n, r):
	return kai[n] * rev_kai[r] * rev_kai[n-r] % mod

tmp1 = 0
tmp2 = 0
mod = 10 ** 9 + 7
for ai in a:
    tmp1 += (ai ** 2) % mod
    tmp1 %= mod
    tmp2 += ai
    tmp2 %= mod

print((tmp2 ** 2 - tmp1) * inv_t[2] % mod)

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

mod = 10**9+7
sa = sum(A)%mod

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

if ans%2== 1:
    ans += mod

print((ans//2)%mod)

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

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

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

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

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

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

total = sum(A_list)

m = 0
for i in range(N - 1):
	A = A_list[i]
	total -= A
	m = (m + A * total) % M

print(m)

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

S = sum(A)
MOD = 10 ** 9 + 7
print(((S * S - sum(x * x for x in A)) // 2) % MOD)

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    sub = 0
    ans = 0
    mod = pow(10, 9)+7
    for i in range(n):
        ans = (ans + sub*a[i])%mod
        sub += a[i]
    
    print(ans)
    
    
    
    
if __name__ == "__main__":
    main()

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

Solution (Python):

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

cA = [A[-1]]

MOD = 10**9+7

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

ans=0
cA.reverse()


for i in range(N-1):
    ans+=A[i]*cA[i+1]
    ans=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, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
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 ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

s = sum(A)
ans = 0

for x in A:
    ans += x * (s-x)
    ans %= mod
ans = ans*pow(2, mod-2, mod)
ans %= mod
print(ans)

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

MOD = 10**9+7
cum = [0 for _ in range(n)]
cum[0] = a[0]
for i in range(1, n):
    cum[i] = cum[i-1]+a[i]

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

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

Solution (Python):
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from  itertools import accumulate

def get_int():return int(stdin.readline().strip())
def get_tuple():return map(int, stdin.readline().split())
def get_list():return list(map(int, stdin.readline().split()))

n = get_int()
ls = get_list()
mod = 10**9+7
pref_sum = list(accumulate(ls))

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

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

mod = 10**9+7

ans = ((sum(A)%mod)**2)%mod
ans -= sum(a*a%mod for a in A)%mod
ans %= mod
ans *= pow(2,mod-2,mod)
ans %= mod

print(ans)

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

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

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

ans *= pow(2,mod-2,mod)
ans %= mod
print(ans)

Solution (Python):



import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
import itertools

input = sys.stdin.readline
mod = 10**9 + 7




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

cumA = list(itertools.accumulate(A[::-1]))[::-1]


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

print(ans % mod)

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


if __name__ == '__main__':
    main()

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

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

sum_a = 0
sum_ex = 0
for ai in a:
    sum_a += ai
    sum_a %= mod
    sum_ex += ai**2
    sum_ex %= mod

ans = (sum_a*sum_a - sum_ex)%mod
ans *= pow(2,mod-2,mod)
ans %= mod
print(ans)

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

MOD = 10**9 + 7
a_cs = [0] * (n + 1)
for i in range(n):
    a_cs[i + 1] = a_cs[i] + a[i]
    a_cs[i + 1] %= MOD

ans = sum(a_cs[i] * a[i] % MOD for i in range(n))
ans %= MOD
print(ans)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

MOD= 10 ** 9 + 7

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

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

Solution (Python):


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  
from itertools import combinations as comb  
from itertools import permutations as permutate
from bisect import bisect_left as bl



from bisect import bisect_right as br
from bisect import bisect







BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None


    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)





from types import GeneratorType


def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func







mod = 1000000007


def inp(): return sys.stdin.readline().rstrip("\r\n")  

def out(var): sys.stdout.write(str(var))  

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

def sep(): return map(int, inp().split())

def strsep(): return map(str, inp().split())


def zerolist(n): return [0] * n

def nextline(): out("\n")  

def testcase(t):
    for p in range(t):
        solve()

def printlist(a):
    for p in range(0, len(a)):
        out(str(a[p]) + ' ')

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

def power(x, y, p):
    res = 1  
    x = x % p  
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  
            res = (res * x) % p

        y = y >> 1  
        x = (x * x) % p
    return res

def ncr(n, r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
    if (n <= 1): return False
    if (n <= 3): return True
    if (n % 2 == 0 or n % 3 == 0): return False
    i = 5
    while (i * i <= n):
        if (n % i == 0 or n % (i + 2) == 0):
            return False
        i = i + 6
    return True


n=int(inp())
N=10**9 + 7
ar=lis()
k=sum(ar)%N
ans=0
for i in ar:
    ans=(ans+(i*(k-i+N)%N)%N)%N
print((ans*power(2,N-2,N))%N)

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

n = int(input())
arr = [int(j) for j in input().split()]

su = sum(arr)
ans = 0
for x in arr:
	ans += x*(su-x)
	ans %= mod
print(ans*pow(2, mod-2, mod) % mod)

Solution (Python):
def gya(n):
    return pow(n,pr-2,pr)
N=int(input())
A=list(map(int,input().split()))
pr=10**9+7
t=0
m=0
for i in A:
    t=(t+i)%pr
    m=(m+i**2)%pr
print(((t**2-m)*gya(2))%pr)