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

MOD = 10 ** 9 + 7
INFI = 10**10

import math
from collections import deque
import itertools
import heapq

from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint




def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    
    n=int(input())
    a=list(map(int,input().split()))
    totalsum=sum(a)%MOD
    total=0
    temp=0
    for i in range(n):
        temp+=a[i]%MOD
        total+=((totalsum-temp)*a[i])%MOD
    print(total%MOD)



if __name__ == "__main__":

    main()

Solution (Python):
import sys
from itertools import accumulate
input = lambda: sys.stdin.readline().rstrip('\r\n')

mod = int(pow(10, 9) + 7)

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

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

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque, defaultdict





def solve():
    N = II()
    A = LI()

    
    
    
    
    MOD = 1000000007
    sm = sum(A)
    ans = 0
    for a in A[:-1]:
        sm -= a
        
        ans += a * sm
        ans %= MOD

    print(ans % MOD)



if __name__ == '__main__':
    solve()

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

Solution (Python):
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
mod = 10 ** 9 + 7
S = sum(A)

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

print(res % mod)

Solution (Python):
import sys

def mmul(a,b):
	return ((a%m)*(b%m))%m

def madd(a,b):
	return (a%m+b%m)%m

def msub(a,b,):
	return (a%m-b%m+m)%m

N=int(sys.stdin.readline())

A=[int(i) for i in sys.stdin.readline().split()]

m=pow(10,9)+7

pre=[0]

for h in range(N):
	pre.append(madd(A[h],pre[h]))

ans=0

for p in range(N-1):
	val=mmul(A[p],msub(pre[N],pre[p+1]))
	ans=madd(ans,val)

print(ans)

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

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

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

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

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

from collections import defaultdict



def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))



def diff(S, i, T):
    res = 0
    for j in range(len(T)):
        if S[i + j] != T[j]:
            res += 1
    return res

def solve():
    N = inp()
    AA = inlt()
    M = 10 ** 9 + 7
    s = 0
    res = 0
    for i in range(N - 1, 0, -1):
        s = (s + AA[i]) % M
        res = (res + (AA[i - 1] * s) % M) % M
    return res

    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))

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


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

Solution (Python):








def solve(N, As):
    mod = 10 ** 9 + 7
    tmp = sum(As)
    mlt = []
    for i in range(N):
        tmp -= As[i]
        mlt.append(tmp)
    ans = 0
    for i in range(N):
        ans += (As[i] * mlt[i]) % mod
        ans %= mod
    print(ans)


if __name__ == '__main__':
    
    N = int(input())
    
    As = [int(i) for i in input().split()]
    

    
    
    
    solve(N, As)

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

p = 10**9+7

sal = sum(al)  % p

import itertools
cumsum = list(itertools.accumulate(al))

temp = 0

for i in range(n):
    temp += (sal-cumsum[i]) *al[i]
    temp = temp % p

print(temp)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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()

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

Solution (Python):
MOD = 10**9 + 7
n = int(input())
A = list(int(x) for x in input().split())
acc = [A[-1]]
for a in reversed(A[:-1]):
    acc.append((acc[-1] + a) % MOD)
acc.reverse()

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

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

mod=10**9+7

inv = pow(2,mod-2,mod)

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

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

res = tmp1**2-tmp2
res %= mod
res *= inv
res %= mod

print(res)

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

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

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

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations, accumulate
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

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

if __name__ == '__main__':
    main()

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

ttl = sum(A)
ttl -= A[0]

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)

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

MOD = 10 ** 9 + 7

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

S = 0
for a in A:
    S += a
    S %= MOD

ans = 0

for a in A:
    t = (S - a) * a
    t %= MOD
    ans += t
    ans %= MOD

fact = [1]
fact_inv = [1]  
for i in range(10):
    new_fact = fact[-1] * (i + 1) % MOD
    fact.append(new_fact)
    fact_inv.append(pow(new_fact, MOD - 2, MOD))

ans *= fact_inv[2]
ans %= MOD

print(ans)

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

ans=sum(a)**2

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

Solution (Python):

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

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

mod = pow(10,9)+7

x = (sum(a)**2)%mod
y = 0
for i in range(n):
	y += (a[i]**2)%mod
print((x-y)*(pow(2,mod-2,mod))%mod)

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

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

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

suff = []

mod = 10**9+7

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


res = 0

for i in range(n):
    
    curr = (suff[n-1-i]%mod * a[i]%mod)%mod
    res = (res%mod + curr%mod)%mod

print(res)

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

n = int(input())
a = [int(x) for x in input().split()]
ans = 0
sum = a[n-1]
for i in range(n-2, -1, -1):
    ans = (ans + sum * a[i]) % mod
    sum += a[i]
ans %= mod

print(ans)

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

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

for a in As:
  ans += (s-a) * a
  
print(ans // 2 % D)

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

MOD = 1000000007

sum_a = sum(a) % MOD 
sum_aa = sum((ai * ai) % MOD for ai in a) % MOD

mod_inv = pow(2, -1, MOD) 

ans = ((((sum_a * sum_a) % MOD) - sum_aa) * mod_inv) % MOD

print(ans)

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

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

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

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


sum = 0

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

print(sum)

Solution (Python):
from itertools import accumulate

def resolve():
    n = int(input())

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

    print(ans)

if __name__ == "__main__":
    resolve()

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

nlist = list(map(int, input().split()))
tsum = sum(nlist)

result = 0
for i in nlist:
    tsum -= i
    result += i*tsum
    result %= (10**9+7)

print(result)

Solution (Python):
import sys

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


def add(a, b, BIGMOD):
    return (a + b) % BIGMOD


def mul(a, b, BIGMOD):
    return (a * b) % BIGMOD


A_Sum = sum(A)
Sum = 0
BIGMOD = 10 ** 9 + 7

for i in range(N - 1):
    A_Sum -= A[i]
    Sum = add(Sum,mul(A[i], A_Sum, BIGMOD),BIGMOD)

print(Sum)

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

B = list(map(lambda x : x**2 , A))
x = sum(A)
y = sum(B)
ans = (x**2 - y) // 2

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

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

p = 10 ** 9 + 7

suma = 0
dsum = 0
for i in a:
  suma = (suma + i) % p
  dsum = (dsum + i ** 2) % p

sa2 = (suma ** 2) % p
ans2 = (sa2 - dsum) % p
if ans2 % 2  == 0:
  ans = ans2 // 2
else:
  ans = (ans2+p) // 2
print(ans)

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

    S = list(reversed(A))

    for i in range(1,N):
        S[i] = (S[i-1]+S[i])%md
    
    S.reverse()

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i in range(N):
    a = As[i]
    ans += (SUM-a)*a
    ans %= mod
print(ans*pow(2, mod-2, mod)%mod)

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

A_acc=[sum(A)]
for a in A:
    A_acc.append(A_acc[-1]-a)

MOD=10**9+7

ans=0

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

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

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

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sums = [sum(a)]
cnt = 0
N = 10 ** 9 + 7

for i in range(n-1):
    sums.append((sums[-1] - a[i]) % N)

for i in range(n-1):
    cnt += a[i] * sums[i+1]
    cnt %= N

print(cnt)

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

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

for i in range(n):
    ans += ((x[i])**2)

ans = (s**2 - ans)//2
print(ans%mod)

Solution (Python):
import sys
import math
import collections
import bisect
import itertools
import decimal




INF = 10 ** 20
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    n = ni()
    a = na()

    cum = [0 for _ in range(n + 1)]
    for i, ai in enumerate(a):
        cum[i + 1] = cum[i] + ai
        

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

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
def main(N, A):
    s = Mint()
    for a in A:
        s += a
    ans = Mint()
    for a in A:
        ans += a * (s - a)
    print(ans // 2)

MOD = 10**9 + 7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

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

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

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

p=10**9+7

SUM=0
for i in range(N):
    SUM+=A[i]
    SUM%=p

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

print(ans)

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

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

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

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

print(ans)

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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





N = getN()
A = getList()

imos = copy.deepcopy(A)
for i in range(N - 1):
    imos[-i - 2] += imos[-i - 1]

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

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

Solution (Python):
N = int(input())
List = list(map(int,input().split()))
LL = [item**2 for item in List]
mod = 10**9 + 7
ListTotal = sum(List)
ans = (ListTotal**2 - sum(LL))//2%mod
print(ans)

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

ans = sum(A)**2
for a in A:
  ans -= a*a
ans //= 2
print(ans%(10**9+7))

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

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, AS):
    sum = 0
    sumSq = 0
    for i in range(N):
        sum += AS[i]
        sum %= MOD
        sumSq += AS[i] * AS[i]
        sumSq %= MOD

    ret = (sum * sum - sumSq) % MOD
    if ret % 2 == 0:
        return ret // 2
    else:
        return (ret + MOD) // 2


def main():
    
    N = int(input())
    AS = list(map(int, input().split()))
    print(solve(N, AS))



T1 = """
3
1 2 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
11
"""

T2 = """
4
141421356 17320508 22360679 244949
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
437235829
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Solution (Python):
import sys

MOD = 10 ** 9 + 7


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = sum(a) ** 2
    for e in a:
        ans -= e ** 2
    ans //= 2
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

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


def mpow(a,b):
    ans = 1
    while (b> 0):
        if b&1:
            ans = (ans*a)%MOD
        a= (a*a)%MOD
        b= b>>1
    
    return ans


n = int(input())
arr =[int(c) for c in input().split()]
s = sum(arr)

ans = 0
for i in arr:
    su = s-i
    ans = (ans + ((su)*i)%MOD)%MOD

ans = ans * mpow(2,MOD-2)
if ans < 0:
    ans+=MOD

print(ans%MOD)

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

par = [0] * n
par[0] = a[0]

mod = 10**9 + 7

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


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

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

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

mod = 10**9 + 7
ans = 0

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

print(ans % mod)

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    A = [a%MOD for a in A]
    s = sum(A)
    ss = sum([a**2%MOD for a in A])
    print((s**2-ss)%MOD * pow(2, -1, MOD) %MOD)


if __name__ == "__main__":
    main()

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

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

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

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

r = 10**9 + 7
s = sum(A)
ans = 0

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

print(ans)

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

sA = sum(As) % (10 ** 9 + 7)
print((sA * sA - sum( (A * A % (10 ** 9 + 7) for A in As) ) ) * pow(2, -1, 10 ** 9 + 7) % (10 ** 9 + 7))

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

x=sum(a)

for i in a:
  ans+=((x-i)*i)
  
ans//=2

print(ans%mod)

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

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

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

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

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

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

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

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

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

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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
aa = a[::-1]
mod = 10**9+7

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

aa = aa[::-1]
ans = 0

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

print(ans%mod)

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

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

print(ans)

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

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

result = 0

MOD = 10**9 + 7

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

print(result)

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

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

MOD = 10**9 + 7
sums = [A[0]]
for a in A[1:]:
    sums.append((a + sums[-1]) % MOD )

alls = 0
for i in range(1, len(A)):
    
    alls += A[i] * sums[i-1]
    alls %= MOD
print(alls)

Solution (Python):
n = int(input())
*arr, = map(int, input().split())
modulo = 10 ** 9 + 7
p = arr.copy()
p.append(0)
for i in range(len(p) - 2, -1, -1):
    p[i] = (p[i] + p[i + 1]) % modulo

ans = 0
for i in range(n):
    ans += arr[i] * p[i + 1]
    ans %= modulo
print(ans)

Solution (Python):
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
a = sum(A)
b = 0
for i in range(N):
    b = (b+A[i]**2)%p
ans = (a*a)%p-b
ans = (pow(2,p-2)*ans)%p
print(ans)

Solution (Python):


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

print(ret%MOD)

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

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

bubun = 0
ans = 0

for i in range(1, N):
    bubun += A[-i]
    ans += A[-(i + 1)] * bubun
    ans = ans % 1000000007

    
print(ans)

Solution (Python):
import sys

MOD = 10**9 + 7

def main():
    N = int(sys.stdin.readline().rstrip())
    A = [int(x) for x in sys.stdin.readline().rstrip().split()]

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


main()

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

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

print(ans)

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