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(map(int,input().split()))

p_mod = (10**9)+7

A_sum = [A[0]]
a_before = A_sum[0]
for a in A[1:]:
    A_sum.append(a+a_before)
    a_before = a+a_before

ans=0
for n in range(N-1):
    ans += (A[n]%p_mod)*((A_sum[-1]%p_mod)-(A_sum[n]%p_mod))%p_mod

print(ans%p_mod)

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

m = 10**9 + 7
s = 0
for i in lis:
    s += i
    s %= m

ans = 0
for i in lis:
    s -= i
    ans += i * s
    ans %= m

print(ans)

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

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
    ans %= MOD

print(ans)

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

Solution (Python):
def ruisekiwa(l):
    
    lst = [0]
    s = 0
    for i,v in enumerate(l):
        lst.append(s + v)
        s += v
    return lst

def solve(n,a):
    r = ruisekiwa(a)
    sm = 0
    for i in range(n-1):
        sm += a[i] * (r[-1] - r[i+1])
    return sm % (10**9 + 7)
def solve2(n,a):
    sm = 0
    for i in range(n-1):
        for j in range(i+1,n):
            sm += a[i] * a[j] % (10**9 + 7)
    return sm


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

    print(solve(n,a))
    



if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    
    SUM = [sum(A)]
    for i in range(1,N):
        SUM.append((SUM[i-1]-A[i-1])%(10**9+7))
    
    ans = 0
    for i in range(N-1):
        ans += A[i]*SUM[i+1]
        ans = ans%(10**9+7)
    
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
MOD = 1000000007
n = int(input())
A = [int(x) for x in input().split()]
result = 0
sumA = sum(A)
for a in A:
    sumA -= a
    result = (result + a * sumA) % MOD
print(result)

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

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

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

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

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

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

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

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

    answer %= (10 ** 9 + 7)

    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 100000
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

n = k()
a = l()

ruiseki = list(itertools.accumulate(a))

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

print(ans % mod)

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

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

Solution (Python):
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce

sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x




	
def main():
	n=ii()
	arr=sorted(li())
	ss=[arr[-1]]
	for i in range(n-2,-1,-1):
		ss.append(ss[-1]+arr[i])
	ss.reverse()
	ans=0
	for i in range(n-1):
		ans+=arr[i]*ss[i+1]
	print(ans%(10**9+7))
			


	

























	
	
	





if __name__ == '__main__':
	main()

Solution (Python):
def square(x):
  y = x**2
  return y


n = int(input())
al = list(map(int, input().split()))
als = list(map(square, al))

print(((sum(al)**2-sum(als))//2)%((10**9)+7))

Solution (Python):
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
mod = 10**9 + 7



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

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

Solution (Python):
def ex_euclid(a, b):
  x0, x1 = 1, 0
  y0, y1 = 0, 1
  z0, z1 = a, b
  
  while z1 != 0:
    q = z0 // z1
    z0, z1 = z1, z0 % z1
    x0, x1 = x1, x0 - q * x1
    y0, y1 = y1, y0 - q * y1
  
  return z0, x0, y0
 
def mod_inv(a, n):
  g, x, _ = ex_euclid(a, n)
  if g != 1:
    print("modular inverse does not exist")
  else:
    return x % n

N = int(input())
A = list(map(int, input().split()))
M = 10**9 + 7
normal = 0
squared = 0
ans = 0
for a in A:
  normal = normal + a % M
  squared = squared + a*a % M
ans = (ans + normal * normal) % M
ans = (ans - squared) % M
ans = ans * mod_inv(2, M) % M
print(ans)

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

Solution (Python):
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7


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





def LI(): return list(map(int, sys.stdin.buffer.readline().split()))




def I(): return int(sys.stdin.buffer.readline())





def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()




def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')







def IR(n): return [I() for i in range(n)]







def LIR(n): return [LI() for i in range(n)]







def SR(n): return [S() for i in range(n)]







def LSR(n): return [LS() for i in range(n)]







def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    a = list(LI())
    res = [0]*len(a)
    res[0] = a[n-1]
    ans = 0
    for i in range(len(a)-1):
        res[i+1] = res[i] + a[n-i-2]
    for i in range(len(a)-1):
        ans += a[i] * res[n-i-2]
    print(ans % mod)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]
arrsum = 0
indSum = 0
for i in A:
    arrsum += i
    indSum += i*i
arrsum = arrsum ** 2
print(((arrsum-indSum)//2)%1000000007)

Solution (Python):
N =int(input())
A = list(map(int,input().split()))
suma = sum(A)
Ans = 0
for a in A:
    suma -= a
    Ans += suma*a
    Ans = Ans % (10**9+7)
print(Ans)

Solution (Python):
from collections import deque

N = int(input())
A = list(map(int,input().split()))
allsum = 0
sums_list = deque()
sums = 0
for i in range(N-1, 0, -1):
  sums = (sums + A[i]) % (10**9 + 7)
  sums_list.appendleft(sums)
for i in range(N-1):
  allsum = (allsum + A[i] * sums_list[i]) % (10**9 + 7)
print(allsum)

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

total=sum(a)

wa=0
for i in range(n):
    wa+=(a[i]*(total-a[i]))
    total-=a[i]

print(wa%(1000000000+7))

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

mod = 10**9+7
s = 0

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

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

s = s*(5*(10**8)+4)

print(s%mod)

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

for a in A:
    S = (a + S) % (2*MOD)
    sq = (a ** 2 + sq) % (2*MOD)

ans = (S ** 2 - sq) % (2*MOD)

print(ans//2%MOD)

Solution (Python):

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

div_num = 10 ** 9 + 7
sum_rest = sum(A_list)
ans = 0
for i in range(N):
    sum_rest -= A_list[i]
    ans = (ans + A_list[i] * sum_rest) % div_num

print(ans)

Solution (Python):
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr  =lambda x: stdout.write(str(x))

mod=1000000007



def findProductSum(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
    return (array_sum_square - 
            individual_square_sum)//2
n=ii()
arr=lii()
print(findProductSum(arr,n)%mod)

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

n = input()
arr = list(map(int, input().split()))
res = findProductSum(arr, len(arr)) % (10**9 + 7)
print(res)

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

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

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

for i in range(n-1):
    a_sum.append((a_sum[i]+a[i+1])%1000000007)

    ans += a_sum[i]*(a[i+1]%1000000007)

print(ans%1000000007)

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

da = [a[n-1] for i in range(n)]
for i in range(n-2, -1, -1):
    da[i] = da[i+1] + a[i]
sum = 0
for i in range(n-1):
    
    sum += a[i] * da[i+1]
    sum %= 1000000007

print(sum)

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

Solution (Python):









def solve():
    n = int(input())
    As = list(map(int, input().split()))

    mod = 10**9+7
    sums = [0] * (n+1)

    tmp = 0
    for i, a in enumerate(As[::-1]):
        tmp += a
        tmp %= mod
        sums[-i-1] = tmp

    total = 0
    for i, a in enumerate(As[:-1]):
        total += a * (sums[i+2])
        total %= mod

    return total


def main():
    print(solve())


if __name__ == "__main__":
    main()

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

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

print(C)

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

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

Solution (Python):
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    Acum = list(accumulate(A))
    ans = 0
    for i in range(N-1):
        ans += A[i] * (Acum[N-1] - Acum[i]) %MOD
        ans %= MOD
    print(ans)



if __name__ == '__main__':
    main()

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

A=list(map(int,input().split()))
zentai=sum(A)
ruiseki_WA=[]
kasu=0
for i in range(N):
    kasu+=A[i]
    ruiseki_WA.append(kasu)
hako=sum(A)
for i in range(N):
    ans+=A[i]*(hako-ruiseki_WA[i])   
print(ans%(10**9+7))

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
key = 1000000007
sum = 0
sum2 = 0
for i in range(N):
    sum += A[i]
    
     

for i in range(N):
    sum2 += A[i]**2
    
     
        
ans = (sum*sum - sum2)//2%key
print(ans)

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

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

sum1 = 0
sum2 = 0
u = 0
for i in range(n):
    u = a[i]
    sum1 = (sum1+u)%(10**9+7)
    sum2 = (sum2+(u**2))%(10**9+7)

sum1 = sum1**2 % (10**9+7)
ans = (10**9+8)//2 * (sum1-sum2) % (10**9+7)
print(ans)

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

N = int(readline().strip())
A = list(map(int, readline().split()))
L = 10**9 + 7

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

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


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


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


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


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    A = LI()
    ans = 0
    tl = 0
    for a in A:
        tl += a
    for i in range(N):
        tl -= A[i]
        ans += (A[i] * tl) % mod
    ans %= mod
    print(ans)



if __name__ == '__main__':
    main()

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

sumA=As[-1]
MOD=10**9+7
ans=0
for n in range(N-1):
    Ai=As[N-2-n]
    ans+=sumA*Ai
    ans%=MOD
    sumA+=Ai
    sumA%=MOD
print(ans)

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

if __name__ == "__main__":
    solve()

Solution (Python):
def main():
    N = int(input())
    As = list(map(int, input().split()))
    ans = 0
    kei = 0
    for i in range(len(As)-1):
        kei += As[-1-i]
        ans += kei*As[-2-i]



    return ans % (10**9 +7)

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

Solution (Python):
n=int(input()) 
a=[int(x) for x in input().split()] 
x=sum(a)**2 
y=sum([x**2 for x in a]) 
z=(x-y)//2 
mod=10**9+7
print(z%mod )

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

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

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

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

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


def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    
    return [w[0],w[1]]


def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

mod = 10**9 + 7
total = 0
for a in A:
    total += a
    total %= mod

sq = 0
for a in A:
    sq += a**2
    sq %= mod

inv = mod_inv(2, mod)

ans = (total**2 - sq) * inv
ans %= mod
print(ans)

Solution (Python):
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
mod=10**9+7
RUISEKI=[0]
for a in A:
    RUISEKI.append((RUISEKI[-1]+a)%mod)

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

Solution (Python):
from sys import stdin,stdout
from collections import defaultdict
import math
from bisect import bisect


n=int(input())
arr=list(map(int,input().split()))
result = 0
su=sum(arr)
s=[]
s1=0
for i in range(n):
    s1+=arr[i]
    s.append(su-s1)

for i in range(0, n): 
    result+=(arr[i]*s[i])
print((result)%(10**9+7))

Solution (Python):

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

wa = sum(A)
out=0
for i in range(N):
    wa -= A[i]
    out+=A[i] * (wa)

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

Solution (Python):


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


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


print(ans)

Solution (Python):
n = int(raw_input())
arr = raw_input()  
v = list(map(int,arr.split(' ')))
su=0
mod=1000000007
for i in v:
    su+=i
su=su*su
x=0
for i in v:
    x+=i*i
ans=(su-x)/2
ans=(ans + mod)%mod
print ans

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

    pref = []

    dup = arr.copy()
    dup.reverse()

    pref.append(dup[0]);
    
    for i in range(1,n):
       pref.append(pref[i-1]+dup[i]);
    
    pref.reverse()

    ans = 0

    for i in range(n-1):
        ans += arr[i] * pref[i+1];

    ans %= 1000000007;

    print(ans)


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

Solution (Python):









def main():
    N = int(input())
    A = list(map(lambda x: int(x), input().split()))

    sum = 0
    mod = 1000000000 + 7

    sumJ = 0
    for j in range(N):
        sumJ += A[j]

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

    print(sum)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
tmp_A = []
tmp_A.append(A[N-1])
for i in range(N-2):
    A0 = tmp_A[i]+A[N-2-i]
    tmp_A.append(A0)
tmp_A.reverse()
sum_A = 0
for i in range(N-1):
    sum_A += A[i]*tmp_A[i]
print(sum_A%(1000000007))

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

Solution (Python):
def read():
    N = int(input())
    As = list(map(int, input().split(' ')))
    return N, As


def func(N, As):
    ans = 0
    s = As[-1]
    for i in range(N - 1):
        t = As[-1 * (i+2)]
        ans += s * t
        s += t
    return ans % (10 ** 9 + 7)

if __name__ == '__main__':
    N, As = read()
    print(func(N, As))

Solution (Python):
import itertools   








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

lis = list(itertools.accumulate(a))

total = 0

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

print(total % MOD)

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

tmp = [0]*N
tmp2 = [0]*N
tmp2[0] = A[0]

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

for i in range(N):
    tmp[i] = sum_A - tmp2[i]

ans = 0
mod = 10**9+7
for i in range(N):
    ans += (A[i]*tmp[i])%mod
    ans = ans%mod
    
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
left =0
right = 0
tmp = 0
for i in range(0,N-1):
    left = A[N-2-i]
    right = right + A[N-1-i]
    tmp += left * right

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

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

mod = 10**9 + 7
ans = 0
prev = a[0]
for i in range(1, n):
    ans += (prev * a[i]) % mod
    prev += a[i]
print(ans % mod)

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

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

a = list(map(int, input().split()))
a = sorted(a, reverse=True)

sum = 0
mult = 0

for i in a:
  mult += (sum * i) 
  sum += i

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
MOD = pow(10, 9) + 7
pairs = sum(a)

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

print(ans)

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

Solution (Python):
from itertools import accumulate

MOD = 10 ** 9 + 7

n = int(input())

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

suffix_sum = list(accumulate(a[::-1]))[::-1]

req_arr = [x -  y for x, y in zip(suffix_sum, a)]

result = sum([(x * y) % MOD for x, y in zip(req_arr, a)])

print(result % MOD)

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

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

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

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

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

sum_ = sum(a_list)
result = 0
for a in a_list:
  sum_ -= a
  result += ((sum_ % mod) * a) % mod
  result = result % mod

print(result)

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

Solution (Python):
import sys
from io import StringIO
import unittest


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

    sum_a = sum(a)
    ans = 0

    for aa in a:
        sum_a -= aa
        ans += aa * sum_a

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


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 2 3"""
        output = """11"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
141421356 17320508 22360679 244949"""
        output = """437235829"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

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

sum = 0
multiplicand=A[0]
for a in A[1:]:
  sum+=multiplicand*a
  multiplicand+=a
print(sum%((10)**9+7))

Solution (Python):




import sys
from io import StringIO
import unittest
import copy

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr2=copy.copy(arr)
    for i in range(1,n):
        arr2[i]=(arr2[i]+arr2[i-1])%mod
    base=arr2[n-1]+mod
    ans=0
    for i in range(n-1):
        ans=(ans+arr[i]*((base-arr2[i])%mod))%mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
from itertools import accumulate

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

MOD = 10**9 + 7

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

print(result)

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

s1=0
for i in range(0,n):
    s1+=a[i]

s3=s1*s1

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

print (((s3-s2)//2)%mod)

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

MOD = (10**9)+7
a_sum = 0
ans = 0
for i in range(n-1):
    a_sum += a_list[n-i-1]
    ans += a_sum * a_list[n-i-2]
    ans = ans % MOD

print(ans)

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

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

L = sorted(L,reverse=True)


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


print(a % (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]
  ans += A[i]*S

print(ans%1000000007)

Solution (Python):
n = int(input())
array = [int(x) for x in input().split(' ')]
s = 0
sums = []
for i in range(n-1, -1, -1):
    if i == n-1:
        sums.append(array[i])
    else:
        sums.append(sums[-1] + array[i])

sums.pop()
for i in range(n-1):
    s += array[i] * sums.pop()

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

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

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

ans = 0
sumA = 0
sumA_2 = 0
for i in A:
    sumA = (sumA + i) % MOD
    sumA_2 = (sumA_2 + i**2 ) % MOD

ans = (sumA * sumA - sumA_2) % MOD

if ans % 2 == 0:
    print(ans//2)
else:
    print((ans + MOD) // 2)

Solution (Python):

import sys

input = sys.stdin.readline
mod = 1000000007


def ST():
    return input().rstrip()


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


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


def LI():
    return list(MI())


N = I()
A = LI()

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

print(ans)

Solution (Python):
from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
MAX=float('inf')
MIN=float('-inf')
MOD=1000000007

n=int(input())
l=list(map(int,input().split()))
l1=list(accumulate(l[::-1]))[::-1]
ans=0
for i in range(1,len(l1)):
	ans+=(l[i-1]*l1[i])%MOD
print(ans%MOD)

Solution (Python):

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


b = [None]*n
b[0] = a[0]

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

con = 0;

for v in range(1,n):
    x = (a[-v] * b[-v-1]) % 1000000007;
    con = (con + x) % 1000000007;

print(con)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
sumA = sum(A)
ans = sum(a*(sumA-a) for a in A) //2 %1000000007
print(ans)

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

ans=0
wa=0

for i in range(n-2,-1,-1):
    wa+=list[i+1]
    ans+=list[i]*wa

print(ans%1000000007)