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


N = int(input())
A = list((input().split(" ")))

values = []
for i in range(N):
    values.append(int(A[i]))


suffixSumArray = values.copy()



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



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

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

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

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

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

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

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

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

Solution (Python):
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data)

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
xs = Is()
mod = 1000000007

acc = xs[0]
ans = 0
for x in xs[1:]:
    ans += acc * x
    ans %= mod
    acc += x

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):
N = int(input())
A = tuple(map(int,input().split()))
mod = 10**9+7
ans = 0
s = (sum(A) - A[0])%mod
for i in range(N-1):
    if s < 0:
        s += mod
    ans += A[i]*s%mod
    ans %= mod
    s -= A[i+1]
print(ans)

Solution (Python):
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

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

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print(int((tmp*tmp-tmp2)//2)%1000000007)

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

mod = 1000000007

s= sum(a)

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

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

Solution (Python):
mod = pow(10, 9)+7
n = int(input())
lt = [int(x) for x in input().split()]

s = sum(lt)
ans = 0
for a in lt:
  s = s - a
  ans+= (a*s)%mod 
print(ans%mod)

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

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

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

Solution (Python):

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

result = 0

s = sum(n_list)
m = 10**9+7

for num in n_list:
    s -= num
    result += num * s % m
    result %= m

print(result)

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

S = [0]*(n+1)
ans = 0

for i in range(n):
    S[i+1] = S[i] + A[i]

for i in range(1,n):
    ans += A[i-1]*(S[-1] - S[i])
    ans %= (10**9 + 7)

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

Solution (Python):
N = int(input())
A = tuple(map(int,input().split()))
mod = 10**9+7
B = [0]*N
for i in range(N):
    B[i] = A[i]**2
s1, s2 = 0, 0 
for i in range(N):
    s1 += A[i]
    s2 += B[i]
s1 = s1**2
ans = (s1 -s2)//2%mod
print(ans)

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




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

Solution (Python):
N = int(input())
A = input().split(" ")
for i in range(len(A)):
  A[i] = int(A[i])
C = 1000000007
mod = 0


sum_A = sum(A)

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

print(mod)

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

def func(N,A):
  result = 0
  S = sum(A) % MOD
  for x in A:
    S -= x
    S %= MOD
    result += x * S
    result %= MOD
  result %= MOD
  return result

if __name__ == "__main__":
  N = int(input())
  A = list(map(int, input().split()))
  print(func(N,A))

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

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

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

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

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

res = 0
for v in A:
	res = (res + v * (s-v)) % MOD

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

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

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

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

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

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

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

print(S//2 % 1000000007)

Solution (Python):


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

s = 0
summation = 0
for i in a_list:
  s += i

for i in a_list:
  s -= i
  summation += i * (s)

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

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

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

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

print(ans)

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

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

Solution (Python):
from itertools import accumulate
def main():
    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)
    
if __name__ == "__main__":
    main()

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    MOD = int(1e09 + 7)
    S = sum(A)
    S -= MOD
    ans = 0
    for i in range(N):
        S -= A[i]
        ans += A[i] * S
        ans %= MOD
    print(ans)


def main():
    
    
    solve()


if __name__ == "__main__":
    main()

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0] * (N+1)


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



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

Solution (Python):
mod = int(1e9 + 7)
n = int(input())
a = input().split()
sum = 0
for x in a:
    sum += int(x)
sum %= mod
ans = 0
for x in a:
    sum -= int(x)
    ans += int(x) * sum
    ans %= mod
print(ans)

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

sum = []

for i in range(N):
  if not sum:
    sum.append(A[i])
  else:
    sum.append(sum[i-1] + A[i])
    
product_sum = 0
    
for i in range(N-1):
  product_sum += A[i] * (sum[N-1] - sum[i])
  
print(product_sum % (10**9 + 7))

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

MOD =  10**9 + 7

ans = 0

t = sum(A)

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

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

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

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

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

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

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

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

N = int(input())


int_list = list(input().split())
int_list = [int(n) for n in int_list]

int_sum = sum(int_list)

sum_result = 0
for num in int_list:
    int_sum -= num
    sum_result += num * int_sum
print(sum_result % target)

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

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

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

Solution (Python):
import itertools
import math

N = int(input())
a_list = list(map(int, input().split()))
a_accumulate = list(itertools.accumulate(a_list))
a_sum = sum(a_list)
result = 0
i = 0
for a in a_list:
  result += a * (a_sum - a_accumulate[i])
  i += 1
print(result%(pow(10,9)+7))

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

mod= 10**9+7

A = sum(a)

ans=0

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

Solution (Python):
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

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

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print(int((tmp*tmp-tmp2)//2)%1000000007)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A2 = list(map(lambda x: x ** 2, A))

sumA = sum(A)
sumA2 = sum(A2)

ans = (((sumA ** 2) - sumA2) // 2) % 1000000007

print(ans)

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

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

for x in a:
    S -= x
    S %= mod
    ans += S * x
    ans %= mod

print(ans)

Solution (Python):
def findProductSum(A, n):
    tmp = (10**9)+7

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

    array_sum_square = array_sum * array_sum

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

    return ((array_sum_square - individual_square_sum) // 2) % tmp

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

print(findProductSum(a,n))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
s=sum(a) % mod
for i in a:
  s-=i
  s%=mod
  ans+=i*s
  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 i in a:
  s-=i
  s%=MOD
  ans+=s*i
  ans%=MOD

print(ans)

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

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

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

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

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

A_sum = sum(A)

r = 0
for i, a in enumerate(A):
    x = A[i]*(A_sum - a)
    r = (r+x) % MOD



r = (r * pow(2, MOD-2, MOD)) % MOD

print(r)

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]
cum_sum = [0]
ans,sum = 0,0


for i in range(len(A)):
    cum_sum.append(cum_sum[i]+A[i])

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

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-1):
    a = A[i]
    S -= a
    ans += a * S % MOD

print(ans % MOD)

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

print(res % mod)

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

for i in range(n-1):
    tmp += arr[i]%1000000007
    ans += tmp*arr[i+1] % 1000000007

print(ans%1000000007)

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

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

ans = 0
double = 0

for i in a:
    double += i*i

ans = (sum(a) * sum(a) - double) // 2
print(ans % (10**9 + 7))

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

B = []
x = 0
for i in range(N-1):
    x += A[i]
    x %= mod
    B.append(x)

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

print(ans)

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
p = 1000000007
 
y = 0
for i in range(n):
    y += a[i]
    y = y % (2 * p)
y = (y ** 2) % (2 * p)
 
x = 0
for j in range(n):
    x += a[j] ** 2
    x = x % (2 * p)
 
z = int(((y - x) / 2) % p)
print(z)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
p = 1000000007
 
z = 0
for i in range(n):
    z += a[i]
    z = z % (2 * p)
z = (z ** 2) % (2 * p)
 
x = 0
for j in range(n):
    x += a[j] ** 2
    x = x % (2 * p)
 
w = int(((z - x) / 2) % p)
print(w)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
p = 1000000007
 
z = 0
for i in range(n):
    z += a[i]
    z = z % (2 * p)
 
y = (z ** 2) % (2 * p)
 
x = 0
for j in range(n):
    x += a[j] ** 2
    x = x % (2 * p)
 
w = int(((y - x) / 2) % p)
print(w)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
r_wa = [a[0]]
for i in range(n) :
  if i>0 :
    r_wa.append(r_wa[i-1]+a[i])

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

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

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

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

l = 0
ass = 0
ans = 0

for i in range(k):
    l += int(num[i])

for i in range(k):
    l -= int(num[i])
    ass += int(num[i]) * l
    

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

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

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

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

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

sum = 0
for x in a:
    sum += x
    sum %= MOD

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

print(ans)

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

MOD = 10**9 + 7

N = int(input())
A = [0] + list(map(int, input().split()))
C = list(accumulate(A))

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

ans %= MOD
print(ans)

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

N = int(input())
A = [0] + list(map(int, input().split()))

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

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

ans %= MOD
print(ans)

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

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

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




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
n=int(input())
a=list(map(int, input().split()))
ans=0
anss=[0]*(n+1)
for i in range(1,n+1):
    anss[-i-1]=anss[-i]+a[-i]
    if anss[-i-1]>10**9+7:
        anss[-i-1]%=10**9+7

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

Solution (Python):
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math


rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	n = int(rl())
	A = list(rli())
	psums = [A[0]]
	ans = 0
	for i in range(1, n):
		psums.append(psums[-1] + A[i])
	for j in range(1, n):
		ans += psums[j-1] * A[j]
		ans %= MOD 
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

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



print(sum%mod)

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

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

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

Solution (Python):
mod = 10**9+7
n = int(input())
input_list = list(map(int,input().split()))
input_len = len(input_list)
remain_num = sum(input_list[1:])
remain_list = [remain_num]
for i in range(1,input_len):
    remain_list.append(remain_list[i-1]-input_list[i])

temp = 0
for i in range(input_len):
    temp = (temp+input_list[i]*remain_list[i])%mod
print(temp)

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

ans = 0
wa = 0
for i in range(n):
    wa = wa + A[i]

wa = wa%mod
wa -= A[0]    

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

print(ans%mod)

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


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

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

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

print(ans)

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

sum_a = 0
mul_a = 0
mod = 1000000007

for a in a_s:
    sum_a += a
    mul_a += a*a
    sum_a %= mod
    mul_a %= mod

ans = sum_a * sum_a
ans %= mod
ans -= mul_a
ans %= mod

n = mod-2
inv = 1
base = 2

while n:
    if n & 1:
        inv = inv*base % mod
    base = base*base % mod
    n >>= 1

ans *= inv
ans %= mod

print(ans)

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def NLI(n):return [[int(i) for i in input().split()] for i in range(n)]
def NLI_(n):return [[int(i)-1 for i in input().split()] for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7

inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

ans=0


s=5*10**8+4

n=I()
a=LI()
A=sum(a)%mo
ans=(A*A-sum([i**2 for i in a]))*s
print(ans%mo)

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

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

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

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

print(ans%mod)

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

sumA, mod, ans = [0], 10 ** 9 + 7, 0
for a in A:
    sumA.append((sumA[-1] + a) % mod)

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

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

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

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

DIV = 10 ** 9 + 7
ans = 0
cur = 0
for i in range(1, N):
  cur += A[i - 1]
  ans += A[i] * cur
  ans %= DIV
  
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-1):
    s-=a[i]
    ans+=a[i]*s
    ans%=mod
print(ans)

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

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

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

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

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

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

Solution (Python):



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

mod=10**9+7

ans=0
accumls=[0]

for i in range (N):
    accumls.append(accumls[-1]+ls[i])

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

print(ans)

Solution (Python):
k = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
S = sum(L) ** 2
for i in L:
  S -= i ** 2

print( (S // 2) % k)

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

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

S = sum(a)

S2 = sum(map(lambda x: x * x, a ))

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

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

Solution (Python):
INF = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
S = [sum(A)]

ans = 0
for i in range(N-1):
    key = S[-1]
    S.append(key - A[i])
    
    ans += (A[i] * S[-1])

print(ans%INF)

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

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

S, T = 0, 0
for i in range(N):
    S = (S + A[i]) % P
    T = (T + A[i] * A[i]) % P

U = (S * S - T) % P
ans = (U * (5 * 10**8 + 4)) % P
print(ans)

Solution (Python):

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

total = 0
total_sum = sum(nums)
for num in nums:
    total_sum -= num 
    total += num * total_sum
    
print(total % 1000000007)

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

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

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

Solution (Python):



def main():
    from itertools import accumulate

    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    summed_a = list(accumulate([0] + a))
    mod = 10 ** 9 + 7
    ans = 0

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

    print(ans % mod)


if __name__ == '__main__':
    main()

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

if __name__ == "__main__":
    n = int(input())
    a = [int(i) for i in input().split()]

    sum_a = sum(a) % MOD

    result = 0 

    for value in a:
        sum_a -= value
        result = int(result + value * sum_a) % MOD
    
    print(result)

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

limit=10**9+7
S=[0]
for i in range(N):
    A[i]=A[i]%limit
for i in range(1,N):
    S.append((S[i-1]+A[-i])%limit)
ans=0
for i in range(N-1):
    ans+=A[i]*S[-1-i]
    ans=ans%limit
print(ans)

Solution (Python):


N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_a = sum(a_list)
total = 0
for i, a in enumerate(a_list):
    total += (a * (sum_a - a)) % mod
    sum_a -= a
total = total % mod
ans = total
print(ans)