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 main(N, A):
    ans = 0
    culm = sum(A)
    for i in range(N-1):
        culm -= A[i]
        ans += A[i]*culm
        ans %= 10**9 + 7
    return ans

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    ans = main(N, A)
    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [x*x for x in a]




s = sum(a)
s = s * s - sum(b)
s = s // 2
s = s % 1000000007

print(s)

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

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

all_sum = 0
count = 1

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

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

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
large_p = 10**9 + 7
from itertools import accumulate
def main():
    n, *a = map(int, read().split())
    a2 = [ae % large_p for ae in a]
    a2a = tuple(accumulate(a2))
    r = 0
    for i1 in range(n - 1):
        t0 = a2[i1] * (a2a[-1] - a2a[i1])
        r += t0
        r = r % large_p
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
list_A = list(map(int, input().split()))
s = sum(list_A)
ans = 0
mod = pow(10, 9) + 7

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

print(ans)

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

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

S = sum(A) % MOD
ans = 0

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

ans %= MOD 
print(ans)

Solution (Python):
num = int(input(""))
val = list(map(int,input().split()))
val_sum = sum(val)
ans = 0
mod = 10**9 + 7

for i in range(num):
    val_sum = val_sum - val[i]
    ans     = val[i] * val_sum + ans
        
print(ans%mod)

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

ans = 0
mod = 10**9+7

S = sum(a)

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

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

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_sum - a[i]
  ans += a[i] *(a_sum)
    
print(ans % (10**9 + 7))

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

B = []
b = 0
e = 10 ** 9 + 7

for i in range(N - 1):
    b += A[N - 1 - i]
    b = b % e
    B.append(b)

result = 0

for i in range(N - 1):
    result += A[i] * B[N - 2 - i]
    result = result % e

print(result)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
k = int((10**9 + 8)/2)
sum = 0
sum_1 = 0

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

for j in range(N):
    sum_1 += A[j]**2
sum_1 = (sum_1)%mod

ans = sum - sum_1
ans = (ans*k)%mod

print(ans)

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

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

Solution (Python):























import math
import copy
import string



INF = int(10**18) 
pi = math.pi

MOD = 1000000007








def my_pow(N, a, M):
    if(a == 0):
        return 1
    else:
        if(a % 2 == 0):
            tempo = my_pow(N, a/2, M)
            return (tempo * tempo) % M
        else:
            tempo = my_pow(N, a - 1, M)
            return (tempo * N) % M





def my_combination(N, a, M):
    res = 1

    for i in range(0, a):
        res *= N - i
        res %= M

    for i in range(0, a):
        res *= my_pow(i + 1, M - 2, M)
        res %= M

    return res





def my_combination_table(N, M, v):
    if(len(v) < N + 1):
        l = N + 1 - len(v)
        tempo = [1] * l
        v.extend(tempo)

    for i in range(1, N + 1):
        v[i] = v[i - 1] * (N - (i - 1))
        v[i] %= M

        v[i] *= my_pow(i, M - 2, M)
        v[i] %= M

    return









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

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


res = sum * sum - sum2
res //= 2
res %= MOD
print(res)

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

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

for i in range(count):
  sum = sum - a[i]
  ans += sum * a[i]
  
answer = ans % mod
print(answer)

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

Solution (Python):



n=int(input())
r=list(map(int,input().split()))
mod=1000000007
s=sum(r)%mod
x=0
for u in r:
  x+=u**2
x%=mod
t=500000004
print((s**2-x)*t%mod)

Solution (Python):
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())),dtype=np.longlong)
mod = 7+10**9
cs = 0
for a in A:
    cs += a
    cs %= mod
cumsum = np.mod(np.cumsum(A),mod)
rev = -1*(cumsum-cs)
ans = 0
for i in range(n-1):
    ans += rev[i]*A[i]
    ans %= mod
print(ans)

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

square_sum_ai = sum(ai) ** 2
sum_ai_square = sum(map(lambda x: x ** 2, ai))

print(((square_sum_ai - sum_ai_square) // 2) % (10 ** 9 + 7))

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

ans = 0
mod = 7 + 10**9

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

print(ans)

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

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

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

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

MOD = int(1e9+7)

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

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

print(ans)

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

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

for j in range(N):
    sum_1 += (A[j]**2)%mod
sum2=sum-sum_1
if sum2<0:
    sum2+=mod
ans=(sum2*500000004)%mod
print(int(ans))

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

cur = 0
res = 0
for i in range(n-1):
    cur = (cur + a[n-1-i]) % mod
    tmp = (a[n-2-i] * cur) % mod
    res = (res + tmp) % mod

print(res)

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

S = sum(A) % MOD
ans = 0

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

print(ans)

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

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

Solution (Python):
import numpy
n=int(input())
l=list(map(int, input().split()))
res=0
mod=10**9+7
l.append(0)
l.reverse()
cum=numpy.cumsum(l)%mod
for i in range(n):
    res+=((l[n-i]%mod)*cum[n-i-1])%mod
print(res%mod)

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

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

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

mod = 10 ** 9 + 7

s = sum(arr) % mod

result = 0
for i in arr:
  s -= i
  s %= mod
  result += s * i
  result %= mod
print(result)

Solution (Python):

import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

val = 0
for a in A:
    val += a * sumA
    val %= 2 * MOD
for a in A:
    val -= a * a
    val %= 2 * MOD
val //= 2
val %= MOD
print(val)

Solution (Python):
def main():
    MOD = 10**9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
   
    a_sum = sum(a)
    
    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):
def main():
    MOD = 10**9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = sum(a)
    ans = 0
    
    for i in range(n):
        ans += a[i] * (a_sum - a[i])
    print(ans // 2 % MOD)
        
        
if __name__ == '__main__':
    main()

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

mod = 10 ** 9 + 7


def cumsum(num, lst):

    cumsumlst = [0] * num

    for hoge in range(1, n):
        cumsumlst[hoge] = (cumsumlst[hoge-1] + lst[hoge]) % mod
    
    return cumsumlst

lst = cumsum(n, a)

ans = 0

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

print(ans)

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

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

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

MOD = 10 ** 9 + 7

tmp = 0

ans = 0

for num in A:
    ans += tmp * num % MOD
    tmp += num
print(ans%MOD)

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

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

MOD = 10 ** 9 + 7

tmp = 0

ans = 0

for num in A:
    ans += tmp * num
    tmp += num
print(ans%MOD)

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

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

MOD = 10 ** 9 + 7

max_edge = sum(A)

tmp = 0

for num in A:
    tmp += num ** 2

print((max_edge ** 2 - tmp) // 2 % MOD)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    K = int(1e9)+7
    acum = [0]
    for i  in range(N):
        acum.append(acum[i]+A[i])
    ans = 0
    for i in range(N):
        ans += A[i]*(acum[N]-acum[i+1])
        ans %= K
    print(ans)
if __name__ == '__main__':
    main()

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

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

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

M = 10**9 + 7

Total = sum(A) -A[0]

ans = 0

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

print(ans)

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

sum = 0
B = []
B.append(0)

for t in range(N):
    B.append(A[t] + B[t])
    
B.remove(0)
    
for i in range(N):
    sum += A[i] * (B[N-1] - B[i])
        
print(sum % (10**9+7))

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(N - 1):
    cum[i + 1] = (cum[i] + A[i + 1]) % mod

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

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

res = 0
ruiseki = 0
for j in range(n):
    if j == 0:
        continue
    ruiseki += a[j-1]
    res = res + a[j]*ruiseki
print(res % ((10 **9)+7))

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

Solution (Python):

MOD = 10 ** 9 + 7


class ModInt:
    def __init__(self, x):
        if type(x) is str:
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(self.x * pow(other.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x)
            if isinstance(other, ModInt)
            else ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(other.x * pow(self.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(other, self.x, MOD))
        )


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

    ans = ModInt(0)

    sm = sum(ls)

    for i in range(n):
        ans += ls[i] * sm

    sub = ModInt(0)
    for i in range(n):
        sub += ls[i] * ls[i]

    ans -= sub

    ans = ans / 2

    print(ans)


main()

Solution (Python):

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

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

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]


mod = 10**9 + 7
N = int(input())
A = inputlist()

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

Solution (Python):
def solve(string):
    _, *a = map(int, string.split())
    return str((sum(a)**2 - sum(map(lambda x: x**2, a))) // 2 % (10**9 + 7))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
from itertools import accumulate


def solve(string):
    _, *a = map(int, string.split())
    ac = list(accumulate(a))
    ans = 0
    for _a, _c in zip(a, ac):
        ans = (ans + _a * (ac[-1] - _c)) % (10**9 + 7)
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
import numpy as np



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


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

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

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

print(ans%mod)

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

tot = 0
num2 = [0]*(N-1)
numtot = sum(num)

for i in range(len(num)-1):
  numtot -= num[i]
  num2[i] = numtot % (10**9+7)
  
  num1 = num[i] % (10**9+7)
  
  tot += num1 * num2[i]
  
  if tot >= (10**9+7): tot = tot % (10**9+7)

print(tot)

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

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

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

d = 10**9 + 7
s = sum(A)
ans = 0
for i in range(len(A) - 1):
    s = s - A[i]
    ans += A[i] * (s)

print(ans % d)

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

Solution (Python):
import sys

MOD = 10**9 + 7

n = int(input())

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

x = pow(sum(a), 2)
y = sum((a[i]**2 for i in range(n)))

sum = (x - y) // 2 % MOD

print(sum)

Solution (Python):
n = int(input())
mod = 10 ** 9 + 7
import numpy as np
a = list(map(int, input().split()))
s=0
ss=0
for i in range(n):
    if i > 0:
        ss += a[i-1]%mod
    s += ss * a[i] % mod
print(s%mod)

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

Solution (Python):
num = int(input())
array = list(map(int,input().split()))
num_sum = 0
tmp_sum = 0

tmp_sum = sum(array)

for a in array:
      tmp_sum -= a
      num_sum += tmp_sum*a

print(num_sum % 1000000007)

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

Solution (Python):
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')
mod = 10**9 + 7

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]








n = I()
a = RI()

s = sum(a)

ls = []
for i in range(n):
    s -= a[i]
    ls.append(s)


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

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

s = input().split(" ")

sumup = 0
for i in s:
  sumup += int(i) 

ans = 0
for i in s:
  r = int(i)
  
  sumup -= r
  
  ans += r*sumup
    
print(ans%(10**9+7))

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

s = input().split(" ")

sumup = 0
for i in s:
  sumup += int(i) 

ans = 0
for i in s:
  r = int(i)
  
  sumup -= r
  
  ans += r*sumup
    
print(ans%(10**9+7))

Solution (Python):
N = int(input())
A = list(int(x) for x in input().split())
B = [0]
a = len(A)
sa = sorted(A)
su = 0
p = 10**9+7

for i in range(a):
    B.append(B[i] + sa[i])

for j in range(a):
    su += sa[j]*B[j]

print(su%p)

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

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

Solution (Python):
p = 10**9+7
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
N = int(input())
A = list(map(int,input().split()))
a1 = sum(A)%p
B = [A[i]**2 for i in range(N)]
a2 = 0
for i in range(N):
    a2 = (a2+B[i])%p
ans = (((a1*a1)%p-a2)%p * pow(2,p-2))%p
print(ans)

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

ans = sum(al)**2
for a in al:
    ans -= a**2

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

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

Solution (Python):
import numpy as np
from numba import njit, i8
import sys
read = sys.stdin.readline
mod = 10 ** 9 + 7


@njit((i8, i8[:]), cache=True)
def main(n, a):
    s = np.zeros(n + 1, dtype=np.int64)
    for i in range(n):
        s[i + 1] = (a[i] + s[i]) % mod
    ans = 0
    for i in range(1, n):
        ans = (ans + a[i] * s[i] % mod) % mod
    print(ans)


n = int(read())
a = np.fromstring(read(), dtype=np.int64, sep=' ')
main(n, a)

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

S = 0
ans = 0
for a in A:
    ans = (ans + a * S) % MOD
    S += a
print(ans)

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

main()

Solution (Python):
N = int(input())
array = list(map(int,input().split()))
num_sum = 0
tmp_sum = 0

tmp_sum = sum(array)

for a in array:
    tmp_sum -= a
    num_sum += tmp_sum*a

print(num_sum%1000000007)

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

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

li = list(map(int,input().split()))
li_1 = []
mod = 10**9+7

a = 0
for i in range(1,len(li)):
    total = li[i] * (a +li[i-1])
    a += li[i-1]
    li_1.append(total)

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

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

result= 0
asum = sum(a)
for j in range(0,n):
  asum -= a[j]
  result += a[j]*(asum)

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

Solution (Python):
import sys
n=int(input())
a=[int(i) for i in sys.stdin.readline().split()]
temps=[a[0]]+[0]*n

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

print(ans)

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

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

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

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
mod = 1000000007
c_sum = [0] * n
c_sum[n - 1] = aaa[n - 1]
ans = 0

for i in range(n - 2, 0, -1):
    c_sum[i] = (c_sum[i + 1] + aaa[i]) % mod

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

print(ans)

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

a = sum(A)

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

print(ans)

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

Solution (Python):
N = int(input())
num_list =  [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
    
    right -= number
    result += (number * right) % mod
print(result % mod)

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

Solution (Python):
from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int(),stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
n=int(I())
a=LI()
sum=0
for i in range(len(a)):
    sum+=a[i]
norm=0
for i in range(len(a)):
    norm+=a[i]**2
print(((sum**2-norm)//2)%(10**9+7))

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

Solution (Python):

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

sq_sum = sum(map(lambda x: x*x, A))
sum_sq = sum(A) * sum(A)
answer = (sum_sq - sq_sum) // 2

print(answer % mod)

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

mod = 10 ** 9 + 7
sums = sum(arr)

answer = 0
for num in arr:
    sums -= num
    answer = (answer + (sums * num)) % mod

print(answer)

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

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

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

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

print(ans)

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

S = sum(A)**2

T = 0
for a in A:
    T+=a**2

S -= T
S //= 2
S%=mod
print(S)

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

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

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

print(score%mod)

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

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

ans = 0
S = sum(A)
for i in A:
    S -= i
    ans += i * S
    ans %= MOD
print(ans)

Solution (Python):







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

mod = 10**9 + 7
all_l = 0
for i in range(n):
    all_l += l[i]
    all_l %= mod

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

print(ans)

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

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

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

ary = [0]*(N-1)
for i in reversed(range(N-1)):
    if i+1 >= (N-1):
        ary[i] = A[N-1]
    else:
        ary[i] = ary[i+1] + A[i+1]

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

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

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

def calculate(n, arr):
    mod = 1000000000 + 7
    result = 0

    rightTotal = sum(arr)
    for i in range(n-1):
        rightTotal -= arr[i]
        result += (arr[i] * rightTotal) % mod

    print(result % mod)




calculate(N, ARR)

Solution (Python):
import numpy as np

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

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
L=list(map(int,input().split()))
s=0
t=0
p=10**9+7
x=5*10**8+4
for i in range(0,n):
	s=(s+L[i])%p
	t=(t+L[i]*L[i])%p

ans=x*(pow(s,2,p)-t)

print(ans%p)