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



import sys
from io import StringIO
import unittest


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)


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

    S = sum(A)
    ans = 0
    for a in A:
        S -= a
        ans += a * S

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


if __name__ == "__main__":
    
    resolve()

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

from itertools import combinations

num = 10**9 + 7
ans = 0

B = []
b = 0
for i in reversed(A[1:]):
    b += i
    B.append(b)
B.reverse()
for x, y in zip(A[:-1], B):
    ans += x*y
    ans %= num
print(ans)

Solution (Python):
import numpy as np
n = int(input())
lst = list(map(int,input().split()))
s = 0
t = 0
for x in lst:
  s += x
  t += (x ** 2) % (10**9+7)

w = (s**2-t) % (10**9+7)
if w % 2 == 0:
  print(w//2)
else:
  print((w+10**9+7)//2)

Solution (Python):

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


def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    
    mod = (10**9) + 7
    print(int(findProductSum(A, n))%mod)

main()

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

sum_ = 0
temp = 0
for i in range(len(a)-1):
    temp += a[-i-1]
    sum_ += temp * a[-i-2]

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

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce
from math import gcd


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


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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.reverse()
ans=0
tempsum=0
for i in range(len(A)-1):
    tempsum+=A[i]
    ans=ans+tempsum*A[i+1]

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

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

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

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

Solution (Python):
from sys import stdin
from collections import defaultdict
readline = stdin.readline
read = stdin.buffer.read
def r_map(): return map(int, readline().rstrip().split())
def r_list(): return list(r_map())

MOD = 10 ** 9 + 7




def main():
    N = int(readline().rstrip())
    A = r_list()
    A.sort()
    ans = 0
    a_dic = defaultdict(lambda: 0)
    for j, a in enumerate(A[:0:-1]):
        i = N - 2 - j
        a_dic[i] += a
        if i > 0:
            a_dic[i - 1] = a_dic[i]
    for i, a in enumerate(A[:-1]):
        ans += a * a_dic[i]
    print(ans % MOD)

if __name__ == "__main__":
    main()

Solution (Python):


n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
s=[]
sum_a=0
for i in range(n-1):
    sum_a+=A[i]
    ans+=sum_a*A[i+1]
    
print(ans%mod)
"""
for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        ans+=A[i]*A[j]
        
print(ans%mod)
"""

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

print(ans%mod)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
prev = 0
s = []
for a in A:
    now = prev + a
    s.append(now)
    prev = now

start = 0
last = s[-1]
for i in s[:-1]:
    ans += (i - start) * (last - i)
    start = i
    
    
print(ans%(10**9+7))

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

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

sm = sum(a)
ans = 0

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

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

Solution (Python):
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

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

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

sum1=0
sum2=0

for i in arr:
    sum1+=i
    sum2+=i**2

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

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

waru = 7 + 1000000000

asum = 0

for i in a:
  asum += i
  
mod = 0
asum -= a[0]
for i in range(len(a)-1):

  mo = (a[i] * (asum)) % waru
  mod += mo

  asum -= a[i+1]
  
print(mod % waru)

Solution (Python):


mod = 10**9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Asum = [0] * N
    Asum[0] = A[N - 1]
    for i in range(1, N):
        Asum[i] = Asum[i - 1] + A[N - 1 - i]
    ans = 0
    for i in range(N - 1):
        ans += (A[i] * Asum[N - 2 - i]) % mod
        ans %= mod
    print(ans)


if __name__ == "__main__":
    main()

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

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

Solution (Python):
n = int(input())
arr  = input().split(" ")
s = int(arr[-1])
mod = 10**9 +7
ans  = 0

def moduloMultiplication(a, b, mod): 
    res = 0; 
    a = a % mod; 
    while (b): 
        if (b & 1): 
            res = (res + a) % mod; 
        a = (2 * a) % mod; 
  
        b >>= 1;
      
    return res; 

for i in range(len(arr)-2, -1, -1):
    t = int(arr[i])
    ans = (ans+  moduloMultiplication(s,t,mod))%mod
    s = (s+t)
print( ans)

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

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

ans = 0
for i in a:
    all_sum = all_sum - i
    ans = (ans + i * all_sum) % (pow(10, 9) + 7)
print(ans)

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

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

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

print(ans)

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

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

Sam = sum(A)

result = 0

for n in range(N-1):
    Sam = Sam - A[n]
    result += Sam * A[n]
    result = result % 1000000007
print(result)

Solution (Python):
n=int(input())
aa=list(map(int,input().split()))
su=sum(aa)
new=[n**2 for n in aa]
sa=sum(new)
x=10**9+7
print((su**2-sa)//2%x)
sa

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

    n = input().rstrip()
    past_a = 0

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        ans += a * past_a
        past_a += a

    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
list_a = [int(x) for x in input().split(' ')]



sum_a = sum(list_a)
sum_a2 = sum([x**2 for x in list_a])

print(((sum_a ** 2 - sum_a2) // 2) % (10**9+7))

Solution (Python):
from sys import stdin, stdout,stderr
import time,math
from collections import defaultdict as dd
 
def pn(ob):stdout.write(str(ob))
def inp():return stdin.readline()

mod = 10**9 + 7

def main():
	n = int(inp())
	arr = list(map(int, inp().split()))

	tot = 0
	res = 0

	for x in arr:
		tot += x
		tot %= mod

	for x in arr:
		tot -= x
		res = (res + (x * tot)% mod) % mod
		res %= mod

	pn(res)
  
if __name__ == '__main__':
	main()

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

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







mysum = sum(A_list)
myans = 0
for n in range(N-1):
    mysum -= A_list[n]
    myans +=  mysum*A_list[n]
print(myans%(1000000007))

Solution (Python):
def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()
d = 10**9 + 7
B = [A[i] % d for i in range(len(A))]

s = 0
s2 = 0
for i in range(len(B)):
    s += B[i]
    s = s
    s2 += B[i] ** 2
    s2 = s2

ans = ((s**2 - s2) // 2) % d

print(ans)

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

wa = sum(suji)
goukei = 0

for i in range(N):
    goukei += suji[i] * (wa - suji[i])
    wa -= suji[i]

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

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

ans = 0
sum = sum(A)

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

print(ans)

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

ruiseki = [0 for _ in range(N+5)]
for i in range(N):
    ruiseki[i+1] = ruiseki[i] + A[i]

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

print(ans)

Solution (Python):
def INT():
    return int(input())

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

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

N = INT()
A = LI()
mod = 10**9 + 7
sm = sum(A) - A[0]
ans = 0

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

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

ans = 0

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

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

Solution (Python):

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

mod=10**9+7

sumA=sum(A)

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

ans=ans//2
print(ans%mod)

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

print(ans)

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

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):
if __name__ == '__main__':
    MODULO = 10**9 + 7
    n = int(input())
    A = list(map(int, input().split()))
    total = 0
    sq = 0
    for i in range(n):
        total = (total + A[i]) 
        sq = (pow(A[i], 2) + sq) 
    total = ((pow(total, 2) - sq) // 2) % MODULO
    print(total )

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

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

total = sum(a)
ans = 0
for i in a:
    total -= i
    ans = (ans + (i * total)) % mod

print(ans)

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

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

sum = 0
squaresum = 0
for i in range(N):
    sum = (sum + A[i]) % MOD
    squaresum = (squaresum + A[i]**2) % MOD
ans = ((sum**2) % MOD - squaresum) % MOD
if ans % 2 == 0:
    print(ans//2)
else:
    print((ans + MOD)//2)

Solution (Python):
N,*A = map(int, open(0).read().split())
Asq=[a**2 for a in A]
S = (sum(A)**2-sum(Asq))//2
print(S%(10**9+7))

Solution (Python):
import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

MOD = 10 ** 9 + 7

N = I()
A = LI()
ans = 0


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

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

       
print(ans%MOD)

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

mod_number = 10**9 + 7
sum_A = sum(A)
total = 0
for i in range(0, N - 1):
    sum_A = sum_A - A[i]
    total += A[i] * sum_A

ans = total % mod_number

print(ans)

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

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    memo = As[0]
    res = 0
    for i in range(N-1):
        res += (memo * As[i+1])%(10**9 + 7)
        memo += As[i+1]

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


if __name__ == "__main__":
    resolve()

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union

























from itertools import accumulate             





def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input():  return sys.stdin.readline().rstrip()
    def ii():     return int(input())
    def isp():    return input().split()
    def mi():     return map(int, input().split())
    def mi_0():   return map(lambda x: int(x)-1, input().split())
    def lmi():    return list(map(int, input().split()))
    def lmi_0():  return list(map(lambda x: int(x)-1, input().split()))
    def li():     return list(input())
    def debug(x): print(x, file=sys.stderr)
    
    
    
    n = ii()
    L = lmi()
    ac = L[:]
    for i in range(n-2, -1, -1):
        ac[i] = (ac[i+1] + ac[i]) % mod
    
    

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



if __name__ == "__main__":
    main()

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

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

Solution (Python):
import numpy as np
from copy import deepcopy
from heapq import heappop, heappush
from bisect import bisect_left, bisect
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations

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

s = 0

S = [0]

for i in range(N):
    S.append(A[i] + S[i])

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

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

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

all_sum = (sum(a) ** 2)
diff = [(a[i] ** 2) for i in range(n)]

ans = (all_sum - sum(diff)) // 2

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

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

Solution (Python):
S = int(input())
A = [int(x) for x in input().split()]

Sum = 0
Asum = sum(A) % 1000000007
for i in range(len(A) -1 ):
    b = A[i]
    Asum = Asum - b
    if Asum < 0:
        Asum = Asum + 1000000007
    Sum = (Sum + Asum * b) % 1000000007

print(Sum)

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

def multipleSum(A, n):
    sum = 0
    for i in range(n):
        sum += A[i]
    mulsum = sum*sum
    insum = 0
    for i in range(n):
        insum+=A[i]*A[i]
    return (mulsum-insum)//2

N = int(input())
A = list(map(int,input().split()))
n = len(A)
print(multipleSum(A,n)%1000000007)

Solution (Python):
import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

dx=[-1,1,0,0]
dy=[0,0,1,-1]


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")


def soe(limit):
    l=[1]*(limit+1)
    l[0]=0
    l[1]=0
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0
    
    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r
    
def solve():
    n=inp()
    s=1
    A=li()
    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] 

    c=((array_sum_square - individual_square_sum)>>1)%mod
    pr(c)
    
for _ in range(1):
    solve()

Solution (Python):
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce
from itertools import groupby, combinations
from heapq import heapify, heappush, heappop



n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return list(map(lambda x: x + d, A))
def ldec(A, d=1): return list(map(lambda x: x - d, A))

def modinv(a, n):
    (x, lastx) = (0, 1); (y, lasty) = (1, 0); p = n
    while p != 0:
       q = a // p; (a, p) = (p, a % p)
       (x, lastx) = (lastx - q * x, x); (y, lasty) = (lasty - q * y, y)
    return lastx % n

N = n1()
A = nn()

mod = 10**9 + 7

s = sum(A) % mod

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

print((ans * modinv(2, mod)) % mod)

Solution (Python):

import sys
input = sys.stdin.readline  
N = int(input())
A = list(map(int, input().split()))
mod =10**9 +7
sum_a =sum(A)
ans =0
for i in range(N-1):
    sum_a -=A[i]
    ans +=(A[i] *(sum_a)) %mod
ans %=mod        
print(ans)

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

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

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
m = 7 + 10**9
print(ans%m)

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

Solution (Python):
n=input()
arr=map(int, raw_input().split())
sums=[0]*n
sums[0]=arr[0]
for i in xrange(1, n):
  sums[i]=sums[i-1]+arr[i];
mod=10**9+7
ans=0
for i in xrange(n):
  ans=(ans%mod+arr[i]*(sums[-1]-sums[i])%mod)%mod
print ans

Solution (Python):
n = int(input())
array = list(map(int, input().split()))
sum = sum(array)
answer = 0
from collections import deque
d = deque(array)
for i in range(n):
    a = d.popleft()
    sum -= a
    answer += a*sum
    answer %= 10**9 + 7
print(answer)

Solution (Python):
import sys
import math

big = 10 ** 9 + 7

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
sum_A = sum(A)

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

print(ans % big)

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

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

sum_sq = pow(sum(A), 2)
sq_sum = sum([a**2 for a in A])

ans = (sum_sq - sq_sum) // 2 % MOD
print(ans)

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


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

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

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

Solution (Python):

import sys


def main():
    N = int( sys.stdin.readline() )
    A_list = list(map(int, sys.stdin.readline().split()))
    
    cum_sum = 0
    A_cum_sum = []

    for i in range(len(A_list)):
        cum_sum += A_list[i]
        A_cum_sum.append(cum_sum)


    mod = 10**9 + 7
    S = 0

    for i in range(len(A_list)):
        S += A_list[i] * ( A_cum_sum[-1] - A_cum_sum[i] )
        S %= mod
    
    print(S)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
import math
import copy
import heapq
import random
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter




input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n - k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv


def renritsu(A, Y):
    
    
    
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    
    return X.flatten().tolist()[0]


class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h + 2) * (w + 2)
        self.wall = wall
        self.get_grid()
        

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        
        return y * (self.w + 2) + x

    def getgrid(self, x, y):
        return self.grid[y][x]

    def get(self, x, y):
        return self.cost[self.pos(x, y)]

    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return

    def show(self):
        for i in range(self.h + 2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i + 1)])

    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return

    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        
        
        
        
        


def solve(nums=0):
    n = getN()
    nums = getList()
    sumn = sum(nums)
    ans = 0
    for num in nums:
        ans += (num * (sumn - num))


    ans //= 2
    print((ans % MOD))


def solve2(nums):
    n = len(nums)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            ans += nums[i] * nums[j]

    return (ans % MOD)
if __name__ == "__main__":
    solve()

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

Solution (Python):

n=int(input())
A=list(map(int,input().split()))
ans=0
mod=10**9+7
s=[0 for _ in range(n+1)]

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

for k in range(1,n):
    ans=(ans+(s[k]*(A[k]%mod))%mod)%mod
print(ans)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
total = 0
sum_A = sum(A)

for i in range(n-1):
    sum_A -= A[i]
    total += A[i] * sum_A

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

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

s = 0
d = 0
for j in range(1,N):
    d += A[j]

for i in range(N-1):
    s += d * A[i]
    if s > 10 ** 9 + 7:
        s = s % (10 ** 9 + 7)
    d -= A[i+1]

print(s)

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

diff = A[0]
res = 0

for i in range(1, N):
    res += diff*A[i]
    diff += A[i]
    res %= 10**9+7
    diff %= 10**9+7
print(res)

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

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

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

rule = 1000000007
s = 0
list_sum = sum(As[1:])
if list_sum >= rule:
    list_sum = list_sum % rule

for i in range(len(As) - 1):
    s += As[i] * list_sum
    if s >= rule:
        s = s % rule
    list_sum -= As[i+1]
    if list_sum < 0:
        list_sum += rule
print(s)

Solution (Python):
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=int(input())
M = 1000000007
lst=list(map(int,input().split()))
x=findProductSum(lst,n)
print(x%M)

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

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

B = A[-1]
ans = 0
for ai in A[-2::-1]:
  ans += (ai*B)%(10**9+7)
  B = (B+ai)%(10**9+7)

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

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

a_lst.reverse()
tmp = a_lst[0]
lst = []
for i in range(1, n):
    lst.append(tmp)
    tmp += a_lst[i]
    tmp %= (10 ** 9 + 7)
lst.reverse()
a_lst.reverse()

ans = 0
for i in range(n - 1):
    ans += (a_lst[i] * lst[i]) % (10 ** 9 + 7)
ans %= (10 ** 9 + 7)
print(ans)

Solution (Python):
def main(N, A):
    div = 10 ** 9 + 7
    s = sum(A)
    ans = 0
    for a in A:
        s = s - a
        mult = ((s % div) * a) % div
        ans += mult
    print(ans % div)

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