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()))
b=[a[0]]
k=0
for i in range(1,n):
    b.append(a[i]+b[i-1])
for i in range(n-1):
    k+=a[i]*(b[n-1]-b[i])
print(k%(10**9+7))

Solution (Python):
l=int(input())
k=list(map(int,input().split()))
s=0
mod=10**9+7
o=sum(k)
p=o**2

s=0
for i in k:
    s=(s+i**2)
    
print((p-s)//2%mod)

Solution (Python):
n,*l=map(int,open(0).read().split())
print((sum(l)**2-sum(i**2 for i in l))//2%(10**9+7))

Solution (Python):
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    N = i_input()
    A = list(i_map())

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

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

    mod = (mod1-mod2)%MOD
    
    answer = ((500000004 * mod))% MOD

    print(answer)
    
    return

if __name__ == '__main__':
    main()

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

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

sum_A = sum(A)

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

Solution (Python):
def main():
    input()
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()

    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()

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

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

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

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

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

L = len(A)
total = 0
tmp = 0
mod = 10**9+7
for y in range(L):
    tmp += A[y]

for x in range(L):
    tmp -= A[x] 
    total += tmp*A[x]
print(total % mod)

Solution (Python):

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N = int(readline())
A = list(map(int,readline().split()))
total = sum(A)
B = [0] * N
for i in range(N):
    B[i] = total-A[i]
ans = 0 
for i in range(N):
    ans += A[i]*B[i]
print((ans//2)%MOD)

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

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



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

A_sum_sq = A_sum * A_sum

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

Answer = (A_sum_sq -
          idv_sq_sum) // 2
print(Answer%(10**9 + 7))

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

sum = 0
for i in a:
    sum += i

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

Solution (Python):
def main():
    input()
    mod = 10**9 + 7
    ar = sorted(map(int, input().split()))
    ar.reverse()

    cnt = ar[0] + ar[1]
    an = ar[0] * ar[1] % mod

    for i in range(2, len(ar)):
        an += cnt * ar[i]
        cnt += ar[i]

    print(an % mod)


if __name__ == '__main__':
    main()

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[i]
  ans += ( A[i] * A_sum )% (10**9 +7)

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

Solution (Python):
import math

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

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

Solution (Python):
import sys
input = sys.stdin.readline
 
N = int(input())
A = list(map(int, input().split()))
score = 0
sum_A = sum(A)
for a in A[:-1]:
  sum_A -= a
  score += a * sum_A
print(score % (10**9+7))

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

threshold = 1000000007
tmp = sum(list_A[1:])
ans = 0
for i in range(N-1):
    if i == 0:
        ans += list_A[i] * tmp % threshold
    else:
        tmp = tmp - list_A[i]
        ans += (list_A[i] * tmp % threshold)
ans = ans % threshold
print(ans)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
licumsum = 0
for i in range(n):
    licumsum += li[i]
asum = 0
for i in range(n):
    asum += li[i]*(licumsum - li[i])
    if asum >= (10**9 + 7)*2:
        asum = asum % ((10**9 + 7)*2)
if asum//2 >= 10**9 + 7:
    print(asum//2-(10**9+7))
else:
    print(asum//2)

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

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

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

Solution (Python):

import sys
sys.setrecursionlimit(1000000)
from collections import deque


N = int(input())

A = list(map(int, input().split()))
ans = 0
S = [0]*N
total = sum(A)
for i in range(N):
    ans += A[i] * (total - A[i])
    total  -= A[i]

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
mod = 1000000000+7
n = int(input())
A = [int(a) for a in input().strip().split()]
s = sum(A)%mod
S = 0

for a in A:
    s = s-a
    S += (s*a)%mod
S = S%mod
print(S)

Solution (Python):
NUM = 1000000000 + 7
N = int(input())
total = 0
A = list(map(int, input().split()))
S = [0] * N
S[0] = A[0]
for i in range(1, len(A)):
  S[i] = S[i-1] + A[i]; 
for i in range(N):
  total += A[i] * (S[N-1] - S[i]);
print(total%NUM)

Solution (Python):
def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): 
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 
    
  return ans

n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
a,b = 0,0
arr_sum = sum(S) 
arr_ssq = arr_sum*arr_sum 
isq_sum = 0
for i in range(n):
  isq_sum += S[i]*S[i] 
  

tot = (arr_ssq - isq_sum)//2 % divisor

print(tot)

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

Solution (Python):
N = int(input())
num_list = list(map(int,input().split()))
num_sum = []

joker = 0

for i in range(N):
    joker += num_list[i]

for i in range(N-1):
    joker -= num_list[i]
    num_sum.append(num_list[i]*joker)
    
print(sum(num_sum)%(10**9+7))

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

Solution (Python):
def solve(n,A):
	mod=10**9+7
	s=0
	for _,x in enumerate(A):
		s+=x
	s=s**2
	squared_terms=0
	for _,x in enumerate(A):
		y=x**2
		squared_terms+=y
	ans=(s-squared_terms)//2
	return ans%mod


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

Solution (Python):


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


if __name__ == '__main__': 
    n=int(input())
    a=input().split()
    for i in range(n):
        a[i]=int(a[i])
    ans=int(findProductSum(a,n))
    ans%=mod
    print(ans)

Solution (Python):









import os
import sys
import numpy as np



def main():
    n = int(input())
    A = list(map(int, input().split()))
    amari = 1000000007
    ans = ((sum(A))*(sum(A)) - sum(a**2 for a in A))
    print(ans//2%amari)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
sum_A = (sum(A)**2) % mod
B = list(map(lambda x: (x**2)% mod,A))
sum_B = sum(B) % mod
print(((sum_A-sum_B)*500000004)%mod)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
len_a = n
sum_list = sum(a)-a[0]
count = 0
for j,i in enumerate(a):
  if j != len_a -1:
    count += i*sum_list
    sum_list -= a[j+1]
    
print(count%1000000007)

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


def main():
    n = int(si())
    l = [int(e) for e in si().split()]
    tot = sum(l)
    mod, ans = 10**9+7, 0
    for i in range(n-1):
        h = l[i]
        tot -= h
        ans = (ans+(tot*h) % mod) % mod
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
sum = 0
for i in range(N):
    sum = sum + A[i]

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

print(res % MOD)

Solution (Python):
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
mod = 10**9+7
mod_sum = 0
a_sum = sum(a)
for i in range(n-1):
    a_sum -= a[i]
    mod_sum += (a[i] % mod) * (a_sum % mod) % mod

print(mod_sum%mod)

Solution (Python):
N = int(input())
a_s = input().split(" ")
a_s = list(map(int, a_s))
asum = sum(a_s)

mod = 10**9 +7
ans = 0
for i in range(len(a_s)-1):
  asum -= a_s[i]
  ans += (asum*a_s[i])%mod
  if ans > mod:
    ans = ans%mod
      
print(ans)

Solution (Python):
from itertools import combinations
import math
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007

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

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(add(result[-1], x))
    return result








inv = cumsum(list(reversed(A)))
c = 0
for i in range(0,N-1):
    c = add(c,mul(A[i],inv[N-i-2]))

print(c)

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

    mod_value = 10**9 + 7
    sum_ = 0
    b_sum = 0
    for i in range(len(A)-1):
        b_sum = b_sum + A[len(A)-i-1]
        sum_ = sum_ + (A[len(A)- i - 2]*b_sum) % mod_value
    print(sum_%mod_value)
main()

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

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

Solution (Python):
N = input()
nums = list(map(int, input().split()))
rests = []
rest_sum = 0
for i in reversed(nums):
    rest_sum += i
    rests.append(rest_sum)

sum_num = 0
for i in range(len(nums)-1):
    sum_num += nums[i]*rests[-(i+2)]
    if sum_num > 10**9 + 7:
        sum_num = sum_num % (10**9 + 7)
    

print(sum_num)

Solution (Python):
N = int(input())
 
A = list(map(int, input().split()))
 
ans = sum(A) ** 2

 
for a in A:
  ans = ans - a ** 2

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

Solution (Python):
d = 10 ** 9 + 7
n = int(input())

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


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

ans = 0

b = 0
for i in range(n):
    b += a[i] ** 2
    b %= d

ans = s ** 2 - b
ans %= d

if ans % 2 == 0:
    ans //= 2
else:
    ans += d
    ans //= 2

print(ans)

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

sumAcol=0
sumA=0
sumtr=0
for i in range(N):
  sumtr+=A[i]**2
  sumAcol+=A[i]
  sumtr=sumtr % (10**9+7)
  sumAcol=sumAcol % (10**9+7)

for i in range(N):
  sumA+=(sumAcol*A[i])%(10**9+7)
  
sumA=(sumA-sumtr)+10**9+7

print(sumA*(5*10**8+4) % (10**9+7))

Solution (Python):
import itertools
N = int(input())
A = list(map(int, input().split()))
ans = 0
sumall = 0
for j in range(N):
    sumall += A[j]
for i in range(N):
    ans += A[i]*(sumall-A[i])
    sumall = sumall - A[i]

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

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

a = input().split()

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

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

print(ans % (1000000007))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve():
    n = II()
    a = LI()
    suma = 0
    for ai in a:
        suma += ai
        suma %= mod
    ans = 0
    for ai in a:
        tmp = suma
        tmp -= ai
        tmp %= mod
        ans += tmp * ai
        ans %= mod
    print(ans * pow(2, mod-2,mod) % mod)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
if __name__ == "__main__":
    n = int(input())

    arr = [int(x) for x in input().split()]
    s1 = sum(arr)
    s2 = sum((x * x for x in arr))

    ans = s1*s1 - s2

    if ans % 2 != 0:
        ans += 10**9+7

    ans //= 2

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
s = 0
for i in range(N):
  s += A[i]
  s %= (10**9+7)
s = s**2
s %= (10**9+7)
 
t = 0
for i in range(N):
  t += (A[i]**2 % (10**9+7))
t %= (10**9+7)
 
ans = (s-t) % (10**9+7)
'''
tmp = (2**1000000005) % (10**9+7)
'''
tmp = 500000004
ans *= tmp
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
sys.setrecursionlimit(10 ** 7)

MOD = 10**9 + 7

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

A = [a % MOD for a in A]
A_d = [(a * a) % MOD for a in A]
res = ((sum(A)**2) % MOD - sum(A_d) % MOD) % MOD
res = res * pow(2, MOD-2, MOD)
res %= MOD

print(res)

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

mymod = 1000000007

def modpow(a, n):
    res = 1
    while(n > 0):
        if n & 1:
            res = (res*a)%mymod

        a = (a * a)%mymod
        n >>= 1

    return res

def modinv(a, b):
    return (a * modpow(b, mymod-2))%mymod

inv2 = modinv

Ai2_sum = 0
for Ai in A:
    Ai2 = (Ai**2)%mymod
    Ai2_sum = (Ai2_sum + Ai2)%mymod

sumA = sum(A)%mymod
sumA_2 = (sumA**2) % mymod

print(modinv(sumA_2 - Ai2_sum, 2))

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

mod = 10**9 + 7
ans = 0




sum = 0
for i in A:
    sum += i

ans = sum * sum
for j in A:
    ans -= j * j
ans //= 2    
ans %= mod





print(ans)

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

from itertools import accumulate
cumsum = list(accumulate(a[::-1]))[::-1]

MOD = 10**9+7
ans = 0
for i,A in enumerate(a[:-1]):
    ans += A * cumsum[i+1]
    ans = ans % MOD
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect














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


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
A = sorted(readInts(),reverse=True)
a = sum(A)**2
nya = 0
for i in range(n):
    nya += A[i]*A[i]
ans = (a-nya)//2
print(ans%mod)

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

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

  

    ans = sum_a % 1000000007

    print(ans)


if __name__ == "__main__":
    solve()

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

A_l = [i for i in A_l if i != 0]

sum_l = [0] * len(A_l)
for i in range(len(A_l)):
    if i == 0:
        sum_l[i] = A_l[i]
    else:
        sum_l[i] = sum_l[i-1] + A_l[i]

for i in range(len(A_l)-1):
    a_sum = a_sum + sum_l[i] * A_l[i+1]
print(a_sum % (10**9+7))

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

    mod = 10 ** 9 + 7

    s = [0] * N
    for i, a in enumerate(A[::-1], 1):
        if i == N:
            continue
        else:
            s[N-i-1] = (s[N-i] + a) % mod

    ans = 0
    for i, a in enumerate(A):
        ans += a * s[i]
        ans %= mod

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin

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

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

    s = s % m
    print(s)
    
if __name__ == "__main__":
    main()

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

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

mod = (10**9)+7
sumA = sum(A)%mod
sumSq = sum([(i*i)%mod for i in A])%mod
r = (((sumA*sumA)%mod)-sumSq) * modinv(2, mod)
print(r%mod)

Solution (Python):

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

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
sum_A = 0
for i in range(N):
    A[i] = A[i] % mod
    sum_A += A[i]

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

print(ans)

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

MOD = 1000000007
SUM = 0
for i in range(N):
  SUM += A[i]
SUM = SUM*SUM
for i in range(N):
  SUM -= A[i]*A[i]
SUM = SUM // 2
SUM %= MOD
print(SUM)

Solution (Python):
n=int(input())
list=input().split()
sum=0
for i in range(n):
 sum+=int(list[i])
sum=sum*sum
sum2=0
for i in range(n):
 sum2+=int(list[i])*int(list[i])
sum-=sum2
sum//=2
sum%=1000000007
print(int(sum))

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

a=(sum(A_ls))**2
b=0
for i in A_ls:
	b+=(i**2)

c=int((a-b)//2)
print(c%(10**9+7))

Solution (Python):
n=int(input())
mod=int(1e9)+7
l=[int(x) for x in input().split()]
sum1=0
sum2=0
for i in range(n):
    sum2=(sum2%mod+l[i]%mod)%mod
for i in range(n-1):
    sum2=sum2-l[i]
    x=(sum2%mod*(l[i]%mod))%mod
    sum1=(sum1%mod+(x%mod))%mod
print(sum1)

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

import time

def solve(N, A):
    ans = 0
    asum = sum(A)
    for i in range(N-1):
        asum -= A[i]
        ans = (ans + A[i] * asum) % MOD
    return ans

if __name__ == '__main__':
    N = int(input())
    A = [int(a)%MOD for a in input().split()]
    ans = solve(N, A)
    print(ans)

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

s=sum(a)

for i in range(1,len(a)+1):
    ans += a[i-1] * (s-a[i-1])
    s = s-a[i-1]
    ans = ans % (10 ** 9 + 7)

print(ans)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()
    ans = 0
    k = 0
    for i in range(n-2,-1,-1):
        k +=a[i+1]
        ans += a[i]*k
    print(ans%(10**9+7))

if __name__=="__main__":
    main()

Solution (Python):
N,*A=map(int,open(0).read().split())
l=[]
s=0
for a in reversed(A):
    s+=a
    l.append(s)
l.reverse()
m=1000000000+7
ans=0
for i in range(N-1):
    ans+=A[i]*l[i+1]
    ans%=m
print(ans)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
M=1000*1000*1000+7
S=[0]*N

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

print("{}".format(SS%M))

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

mod = 10**9+7

sums = []
current_sum = 0
for a in A[1:][::-1]:
    current_sum += a
    sums.append(current_sum)
sums = sums[::-1]

ans = 0
for a, b in zip(A[:-1], sums):
    ans += a * b
    ans = ans % mod

print(ans)

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

ans = 0

sum_a = sum(a)


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

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

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

for i in range(0, len(a) - 1):
  suma -= a[i]
  r += a[i] * suma
print(r % (10 ** 9 + 7))

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


mod = pow ( 10,  9 ) + 7 ;

arr2 = [ 0 for x in range ( N ) ] ;
for x in range ( N -1 , 0 , -1 ) :
	if x == N -1  :
		arr2[x] = arr[x] ; 
	else :
		arr2[x] = ( arr[x] + arr2[x+1] ) % mod ;
t = 0 ; 
for x in range ( N -1 ) : 
	t += ( arr[x] * arr2[x+1] ) % mod ;
	t %= mod ; 
print ( t ) ;

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

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

MOD = 1000000007
s = sum(A)

ans = 0

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

print(ans % MOD)

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

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

suma = 0

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

for i in range(n):
	suma -= a[i]
	a[i] *= suma


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

print(sumall % 1000000007)

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

mm = 10**9 + 7

def cumsum(a):
    s = [0]
    for i in range(len(a)):
        s.append(s[i]+a[i])
    return s

S = cumsum(a)

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

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

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

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

mod = 10**9 + 7





print(ans%mod)

Solution (Python):
def main():
    n=int(input())
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()

    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()

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

Solution (Python):

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9+7
    norm = 0
    for a in A:
        norm += a**2
        
    ans = ((sum(A))**2 - norm) % mod
    ans = ans * modinv(2, mod)
    print(int(ans%mod))


if __name__ == '__main__':
    main()

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

sum_until_here = 0
ans_sum = 0
for i in range(n):
    ans_sum += a[i] * sum_until_here
    sum_until_here += a[i]
print(ans_sum % (1000000000 + 7))

Solution (Python):
N = int(input())
A = [int(a) for a in input().split(' ')]
S = [0] * N
s = 0

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


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

print(s)

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

print(ans)

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

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

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


m = 10 ** 9 + 7
def main():
    s = sum(a)
    ss = 0
    r = 0
    for nn in range(n):
        ss += a[nn]
        r += a[nn] * (s - ss)
    print(r % m)
    return

main()

Solution (Python):
mod = 1000000007


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


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2))**2 % mod
    else:
        return power(x, int(y/2))**2 * x % mod


def div(a, b):
    return mul(a, power(b, mod-2))


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

s = int(0)
r = int(0)
for a in A:
    s = int(s + a)
    r = int(r + a * a)

print(div(s * s - r, 2))

Solution (Python):
import itertools
import numba
from numba import jit, i8
import decimal


def calc(x):
    return (x % (10 ** 9 + 7))




n = int(input())

a = list(map(int, input().split()))
rev_a = a[::-1]

acc_a = list(itertools.accumulate(rev_a))


MOD = 10**9 + 7
ans = 0
num = len(a)


for i, val in enumerate(a):
    if (i == num - 1):
        break
    
    temp = acc_a[num - 1 - i - 1] % MOD
    
    
    
    
    ans += (temp * val) % MOD

print(ans % MOD)

'''
@jit
def calc(lis):
    ans = 0
    num = len(lis)
    for i in range(num):
        for j in range(i + 1, num):
            temp = (lis[i] * lis[j]) % MOD
            ans += temp

    return ans


aa = calc(a)
print(aa)
'''

'''
for i in itertools.combinations(a, 2):
    temp = (i[0] * i[1]) % MOD
    ans += temp

print(ans)
'''

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9+7)

all = pow(sum(A), 2, mod=mod)%mod
d = 0
for a in A:
    d += pow(a,2)
    d = d%mod

print(int((all-d)*pow(2, mod-2, mod=mod))%mod)

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

sum = 0
for i in range (N):
    sum += A[i] % MOD

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

ans = ans % MOD
print(ans)

Solution (Python):
s =0
r =0

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

for e in l:
	r += e*s
	s += e

mod =int(1e9+7)
print( r %mod )

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 main():
  N = int(input())
  A_lst = list(map(int, input().split()))
  
  sum = 0
  for i in A_lst:
    sum += i
    sum = sum % (10**9 + 7)
  
  sum2 = 0
  for j in A_lst:
    sum = ((sum-j) % (10**9 + 7))
    sum2 += j * sum
    sum2 = sum2 % (10**9 + 7)

  print(sum2)
  
main()

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

totalsqr = (sum(l))**2

individualsqrsum=0
for i in l:
    individualsqrsum += i**2

ans = (totalsqr  - individualsqrsum)  // 2 
ans = ans%(10**9 + 7)
print(ans)

Solution (Python):
MOD = 1000000007

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

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

array_sum_square = pow(array_sum,2)

individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum+= pow(a[i],2)

ans=(array_sum_square - individual_square_sum) //2
print(ans%MOD)

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)