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


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key
from bisect import bisect_left


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


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

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

def bindex(a,x):
    i = bisect_left(a,x)
    if i != len(a) and a[i] == x:
        return i
    return None

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N = intinput()
    indatas = list(mulinputs())

    
    
    
    
    
    
    
    ruiseki = []
    for _ in range(len(indatas)):
        ruiseki.append(ModInt(0))
    ruiseki[0] = ModInt(indatas[0])
    for i in range(1,len(indatas)):
        ruiseki[i] = ModInt(indatas[i]) + ruiseki[i-1]
    ans = ModInt(0)
    b = ruiseki[len(ruiseki)-1]
    for i in range(len(indatas)):
        a = ModInt(indatas[i])
        b = b-a
        ans += a*b
    print(ans)

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

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


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

        
        

print(ans%(1000000000+7))

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

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

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





def exEuclid(a, b):
    if (b==0):
        return (a, 1, 0)
    else:
        (dd, xx, yy) = exEuclid(b, a % b)
        return (dd, yy, xx - (a//b)*yy)

def main(n,a):
    MOD=10**9+7
    sum1=0
    sum2=0
    for i in range(n):
        sum1=(sum1+a[i])%MOD
        sum2=(sum2+(a[i]*a[i]))%MOD

    aa=(sum1*sum1-sum2+MOD)%MOD

    d,x,y=exEuclid(2,MOD)
    if x<0:
        x+=MOD
    

    return (aa*x)%MOD

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    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', '')
import sys
import itertools
import copy


def main():
    N = I()
    a_list = LI()
    sum_list = []
    
    
    
    
    cnt = 0
    total = sum(a_list)
    
    current_sum = 0
    for i in range(N):
        current_sum += a_list[i]
        sum_list.append(total - current_sum)
    
    ans = 0
    for i in range(N):
        ans += sum_list[i] * a_list[i]
        ans =  ans % (10**9 + 7)
    print(ans)
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


    
    
    
    
    

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
aa=sum(lst) % (10**9+7)

new_lst=[]
temp_1=aa
for i in range(n-1):
    temp_1-=lst[i]
    new_lst.append(temp_1)


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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
total=0
ans=0
d=[0]*210000

for i in range(N):
    total+=A[i]
    d[i]=total

for j in range(N):
    ans+=A[j]*(total-d[j])

print(ans%1000000007)

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

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

a1 = sum(a)
a2 = sum([x*x for x in a])

print(((a1**2-a2)//2)%MOD)

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

s = sum(lis) ** 2
ss = sum([i ** 2 for i in lis])

print(((s - ss)//2)%(10**9+7))

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
p = 0
c = len(A) - 1
total = 0
while 0 < c:
    p += A[c]
    total = total + p * A[c-1]
    if total >= 1000000007:
        total %= 1000000007
    c -= 1

print(total)

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

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

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

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

X = 0
Ans = 0

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

print(Ans)

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

result = 0

sum_a = 0
for i in range(n):
    sum_a = (sum_a + a[i]) % m

result = 0
for i in range(n):
    x = a[i]
    sum_a -= x
    result = (result + x*sum_a) % m

if(result < 0):
    result += m
print(result)

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

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

modsum = 0
A = list(map(int, input().split()))
for a in A:
    modsum = (modsum + a) % MOD

count = 0
for a in A[:-1]:
    modsum -= a
    while modsum < 0:
        modsum = MOD + modsum
    count = (count + (modsum * a) % MOD) % MOD
print(count)

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

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

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

cnt = 0
k = 0
M = 10**9 + 7

for i in range(0, N-1):
    k += An[i]
    cnt += k * An[i+1]

ans = cnt % M
print(ans)

Solution (Python):
N = int(input())
A= list(map(int,input().split()))
mod_num = int(1.0e+9 + 7)
rest = 0
temp = 0

for i in range(N-1):
  temp+=A[i]
  rest += temp*A[i+1]
  rest = rest%mod_num

print(int(rest%mod_num))

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

Solution (Python):
n=int(input())
s=input()
m=list(s.split())
a=0
b=0
for i in range(0,n):
  a=a+int(m[i])
  b=b+(int(m[i])*int(m[i]))
l= ((a**2)-b)//2
l=l%1000000007
print(l)

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

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

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

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

def mod(x):
	return x % 1000000007

sa = sum(A[1:])
s = mod(A[0] * sa)

for a in A[1:-1]:
	sa -= a
	s = mod(s + a * sa)

print(s)

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

N = 2
FAC = [1]
INV = [1]
for i in range(1,N+1):
  FAC.append((FAC[i-1]*i) % MOD)
  INV.append(pow(FAC[-1],MOD-2,MOD))

  
s = 0
for ai in a:
  s += ai
  s %= MOD
ans = 0
for ai in a:
  ans += ai*(s-ai)
  ans %= 10**9+7
print((ans*INV[2])%MOD)

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

for i in range(n - 1):
    main = a[i]
    a_sum = a_sum - main
    res =  (res + main * a_sum % mod) % mod
print(res)

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

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

a = sum1*sum1
li = [x**2 for x in L]

b = sum(li)

print(((a-b)//2)%mod)

Solution (Python):
def main():

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


    m = 10**9 + 7
    ans = 0
    s = []
    total = sum(a)
    s.append(total-a[0])
    for i in range(1,n):
        s.append(s[i-1] - a[i])
    for i in range(n):
        tmp = s[i] % m
        ans += tmp * a[i]
    
    print(ans%m)

if __name__=='__main__':
    main()

Solution (Python):
n = input()
a = [int(num) for num in input().split(" ")]

mod_value = 10**9 + 7

sum = 0
total = 0
for i in reversed(range(1, len(a))):
    sum += a[i]
    total += a[i-1] * sum

print(total%mod_value)

Solution (Python):
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
sums = []
for n in nums[1:][::-1]:
    if sums:
        sums.append(sums[-1]+n)
    else:
        sums.append(n)
sums.reverse()

for i, ni in enumerate(nums[:-1]):
    res += ni*sums[i]
    res %= 10**9 + 7
print(res)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = 10**9+7
sa = sum(a)
c=0
for i in a:
    c +=(i*i)%(2*b)

print(int((sa%(2*b)*sa%(2*b)-c%(2*b))/2)%b)

Solution (Python):

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size, init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]


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


def II():
    return int(input())


def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)


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


K = 10**9+7
N = II()
a = np.array(acinput())
a = a[a != 0]
N = len(a)
s1 = 0
for i in range(N):
    s1 += a[i]
    s1 %= K

s1 %= K



s = (s1*s1) % K
T = 0
for i in range(N):
    T += a[i]*a[i]
    T %= K


tmp = modinv(2, K)
s += K
print((s-T)*tmp % K)

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

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

import copy
B = copy.copy(A)
C = sum(B)
ans = 0

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

Solution (Python):

N = int(input())
li = list(map(int, input().split()))
MOD_NUMBER = 10**9+7
nizyo_list = [i**2 for i in li]
ans = (sum(li)**2-sum(nizyo_list))//2
print(ans % MOD_NUMBER)

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

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

Solution (Python):
n = input()
a = list(map(int, input().split()))
sum_a = sum(a)
count = 0
for i, v in enumerate(a):
    sum_a -= v
    count += v * sum_a

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

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

Solution (Python):


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

ans = 0

sums = [0] * (n - 1)

for j in range(n - 1):
    if j == 0:
        sums[0] = nums[0] % x
    else:
        sums[j] = (sums[j - 1] + nums[j]) % x

for i in range(1, len(nums)):
    ans += sums[i - 1] * nums[i]
    ans = ans % x

print(ans)

Solution (Python):
n = int(input())
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i)  % 1000000007)
    
ans = 0 
total = []
curtotal = sum(arr)
total.append(curtotal)
for i in range(n):
    curtotal -= arr[i]
    total.append(curtotal)
for i in range(n):
    total[i] = total[i] % 1000000007

for i in range(n - 1):
    curnum = arr[i]
    tempans = curnum * total[i + 1]
    if tempans >= 1000000007:
        tempans = tempans % 1000000007
    ans += tempans

if ans >= 1000000007:
    print(ans % 1000000007)
else:
    print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = 0
    m0 = 10**9+7
    Ar = [0]*N
    sum0 = 0
    for i in reversed(range(N)):
        sum0 = (sum0 + A[i]) % m0
        Ar[i] = sum0

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

if __name__ == '__main__':
    main()

Solution (Python):
from sys import setrecursionlimit
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush
from time import time
import re
setrecursionlimit(10**9)
mod=10**9+7
inf=10**18

n=int(input())
a=[int(x) for x in input().split()]
cum_a=[]
for i in range(n):
    if i==0:cum_a.append(a[i])
    else:cum_a.append(cum_a[-1]+a[i])
ans=0
for i in range(n-1):
    ans+=a[i]*(cum_a[n-1]-cum_a[i])
    ans%=mod
     
print(ans)

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
ans=0
i=0
S=sum(l)
while i<len(l)-1:
  S=S-l[i]
  ans+=l[i]*S
  i+=1
print(ans%1000000007)

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

for i in range(N):
  total+=(an-A[i])*A[i]
s = total//2
print(s%mod)

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

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

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

print (ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A_sum = sum(A[1:])

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

Solution (Python):
n = int(input())
M = 1000000007
a = input().split()
sum = 0
sq_sum = 0
for x in a:
    y = int(x)
    sum += y
    sq_sum += (y*y)
sum = sum * sum
ans = abs(sum - sq_sum)//2
ans = (ans + M) % M
ans = int(ans)
print(ans)

Solution (Python):

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

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

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

Solution (Python):
from itertools import accumulate


def main():
    n = int(input())
    array = [int(x) for x in input().split()]
    acc = accumulate(array)
    mod = 10 ** 9 + 7
    ans = 0
    for i, ai in enumerate(acc):
        if i == n - 1:
            continue
        ans += ai * array[i + 1]
        ans %= mod
    return ans


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

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

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
aa=sum(lst) % (10**9+7)

new_lst=[]
temp_1=aa
for i in range(n-1):
    temp_1-=lst[i]
    new_lst.append(temp_1)


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

Solution (Python):
M=1000000007
def findProductSum(A, n): 
    s = 0
    for i in range(n): 
        s+=A[i] 
    array_sum_square = s*s
    individual_square_sum = 0
    for i in range(n): 
        individual_square_sum += A[i]*A[i]
    return (array_sum_square -individual_square_sum) // 2
n=int(input())
a=list(map(int,input().split()))
print(findProductSum(a,n)%M)

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

for j in range(l-1):
    ans = (ans + Alst[j] * Blst[j+1])%(10**9 + 7)

print(ans)

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

Solution (Python):
from itertools import accumulate
N=int(input())
A=list(map(int,input().split()))
p=10**9+7
ans=0
B=list(accumulate(A[::-1]))
for i,value in enumerate(A):
    if i==(N-1):
        break
    ans+=((value%p)*(B[-2-i]%p))%p
    ans=ans%p
print(ans)

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

total = 0
for i in range(len(a)-1):
    if(i == 0):
        before_sum = sum(a) - a[i]
    else:
        before_sum -= a[i]
    total += a[i] * (before_sum) 


print(total%mod)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	n = int(input())
	
	
	al = lin()
	
	d = sum(al)
	
	ret = 0
	for v in al:
		d -= v
		ret += v*d
		ret = ret % mod
	return ret
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

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

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

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
B = A[::-1]

mod_n = 10**9+7

cum_A = [0]
for i in range(n-1):
  cum_A.append(cum_A[i]+B[i])
  
ans = 0
cum_B = cum_A[::-1]
for i in range(n-1):
  ans += A[i]*cum_B[i]%mod_n
  
print(ans%mod_n)

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

ans = 0
tmp_val = 0
for i in range(n):
  tmp_val = (tmp_val + a[i]) % c

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

print(ans % c)

Solution (Python):
def fastSumPair(A):
    L = len(A)
    M = 1000000007
    
    
    
    
    
    A_1_sum = 0
    for i in range(0, L):
        A_1_sum = (A_1_sum + A[i]) 
    
    A_1_sum = (A_1_sum ** 2) 
        
    
    A_2_sum = 0
    for i in range(0, L):
        A_2_sum = (A_2_sum + A[i] ** 2) 
                  
    return int((A_1_sum - A_2_sum) // 2) % M        

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

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

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

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

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

ruisekiwa = [0]*N
wa = sum(A)%M

result = 0
for i in range(N):
    wa -= A[i]
    result = (result+(A[i]*wa)%M)%M

print(result)

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
y=0
for i in range(n):
    y+=a[i]**2

ans = (x**2 - y)//2

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

print(int(ans))

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

s_1 = 0
s_2 = 0
m = 10 ** 9 + 7
for i in range(n):
    s_1 += a[i] % m
    s_2 += (a[i] ** 2) % m
s = (s_1 * s_1 - s_2) * pow(2, -1, m) % m
print(s)

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

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

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):
def resolve():
    N = int(input())
    A = [int(i) for i in input().split(maxsplit=N)]
    presum = [0 for _ in range(N + 1)]
    for i in range(N):
        presum[i + 1] = presum[i] + A[i]
    sumA = 0
    for i in range(1, N):
        sumA += (A[i] * (presum[i])) % (10**9 + 7)
    print(sumA % (10**9 + 7))


resolve()

Solution (Python):
n = int(input())
a = [int(s) for s in input().split()]
b = []
val = 0
sum_val= 0
for i in range(0, n):
    b.append(a[i] * sum_val) 
    sum_val+= a[i] 
val = sum(b)
print(val % (10 ** 9 + 7))

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

print(ans)

Solution (Python):
n=int(input())
lista=list(map(int,input().split()))
listb=[]
for i in lista:
	listb.append(i)
for i in range(1,n):
	listb[i]=listb[i]+listb[i-1]

sum1=0
for i in range(n-1):
	sum1+=lista[i]*(listb[-1]-listb[i])
sum1=sum1%(1000000007)
print(sum1)

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

sum1 = sum(As) % mod2
squared1 = (sum1 ** 2) % mod2

squared2 = 0

for i in range(N):
    squared2 += (As[i] ** 2) % mod2

print(int((squared1 - squared2) / 2) % mod)

Solution (Python):
from itertools import accumulate
from sys import stdin


class ModInt:
    def __init__(self, x):
        self.x = x % MOD

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

    __repr__ = __str__

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

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

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


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    a_ = map(ModInt, A)
    arr = list(accumulate(a_))
    ans = 0
    for i in range(N - 1):
        ans += A[i] * (arr[-1] - arr[i])
    print(ans)


MOD = 1000000007
main()

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

Solution (Python):
N = int(input())
alist = list(map(int, input().split()))
import numpy as np
Sum_a = 0
Sum_j_list = np.cumsum(alist)
for i in range(N-1):
  Sum_j = int((Sum_j_list[N-1] - Sum_j_list[i]) % int(1e9+7))
  Sum_a += (alist[i] * Sum_j) % int(1e9+7)
print(int(Sum_a % int(1e9+7)))

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

Solution (Python):

N = input()
a = []
for i in input().split():
    a.append(int(i))

MOD = 1000000007
MOD2 = 2*MOD

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

buf_b = 0
for x in a:
    buf_a -= x
    buf_b += buf_a * x
    buf_b %= MOD

print(buf_b)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
summ1 = 0
answer = 0
temp = 0
summ2 = 0
summ3 = 0
for i in range(N):
    summ1 += A[i]
for l in range(N):
    summ3 += A[l]
    summ2 += A[l]*(summ1-summ3)
answer = summ2 % 1000000007
print(answer)

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

m = 1000000007

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

ans = ans//2
ans = ans % m

print(ans)

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

MOD = 10**9 + 7
A_mod = [a%MOD for a in A]

R = sum(A_mod)

ans = 0

for a in A_mod:
    R -= a
    ans = (ans + a%MOD * R%MOD)%MOD
    
print(ans)