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 math

num = int(input())
array_str = input().split(" ")
array = [int(n) for n in array_str]

value=0
a=0
b=0
modbase=int(7+math.pow(10,9))
for i in range(len(array)-1):
  bindex=i*(-1)-1
  b+=array[bindex]
  a=array[bindex-1]
  value+=a*b
print(value%modbase)

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


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

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

su = sum(A) % (10**9+7)
ans = 0

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

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

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

mod = 10 ** 9 + 7
sum_A = sum(A)

ans = [0] * (N - 1)
for i in range(N):
    if i == N - 1:
        break
    sum_A -= A[i]
    ans[i] = sum_A
    


ans_num = 0
for i in range(len(ans)):
    ans_num += A[i] * ans[i]

print(ans_num % mod)

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

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

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


main()

Solution (Python):


import sys

DEBUG = False


def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep=" "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


MOD = int(1e9 + 7)


def mod_inv(a, b, mod):
    return (a * pow(b, mod - 2, mod)) % mod


def solve(as_):
    all_sum = 0
    for a in as_:
        all_sum = (all_sum + a) % MOD
    ans_x2 = 0
    for i in range(0, len(as_)):
        ans_x2 = (
            ans_x2 + ((MOD + (all_sum - as_[i]) % MOD) % MOD) * as_[i] % MOD) % MOD

    return mod_inv(ans_x2, 2, MOD)


def main():
    _n = read(int)
    as_ = read_list(int)
    print(solve(as_))


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
nn = int(input())
aa = list(map(int, input().split()))
bb = [0]*(nn-1)
mysum = sum(aa)
mydiff = 0

for i in range(1,nn):
    mydiff += aa[i - 1]
    bb[i-1] = mysum - mydiff

finalsum = 0
for i in range(nn-1):
        finalsum += aa[i]*bb[i]
        finalsum = finalsum % (10**9 + 7)

print(finalsum)

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

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

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

Solution (Python):
N=int(input())
num=list(map(int,input().split()))
goukei=0
for i in range(N):
    goukei += num[i]
    goukei = (goukei%(10**9+7)) 
temp=goukei
sn=0
for i in range(N):
    temp=temp-num[i]
    sn+=num[i]*temp
print(sn%(10**9+7))

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

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

"""

1 2 3 4

1*2, 1*3 1*4
2*3 2*4
3*4
1 6 3 5
1*6 1*3 1*5 = 1 * (6 + 3 + 5)
3*5 
10 ** 5 * 
"""
ans = 0
s = sum(A) % mod
for a in A:
    s -= a
    s %= mod
    ans += a * s % mod
    ans %= mod

print(ans)

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

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

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

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

big = pow(10,9) + 7
sums = pow(sum(a),2)
a_2 = list(map(lambda x: x ** 2, a))

print(((sums-sum(a_2)) // 2)%big)

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

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

M = 1000000007
A = sum(a)
A *= A
B = 0
for ai in a:
    B += ai * ai
print(int((A - B) // 2 % M))

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

result = 0
MOD = 10**9+7

S = sum(As)

for i in range(len(As)-1):
    S -= As[i]
    tmp = As[i] * S
    result += tmp
    result %= MOD

print(result)

Solution (Python):
def sumproductsofpairs(lst):
    total = 0
    psum = 0
    for x in lst:
        total += psum * x
        psum += x
    return total%(1000000007) 
b=int(input())
A=list(map(int,input().split()))
print(sumproductsofpairs(A))

Solution (Python):
""" C
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, A):
    M = pow(10, 9) + 7
    result = 0
    S = sum(A)
    for i in range(len(A)):
        S = S - A[i]
        result = (result + A[i] * S) % M
    return result

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))

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

    mod = 10**9+7
    s = 0
    sq = 0
    for i in range(n):
        s += a[i]
        sq += (a[i])**2

    print(((s**2-sq)//2)%mod)

resolve()

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
sum_a = sum(a_list)
ans = 0
m = 10 ** 9 + 7

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

print(ans)

Solution (Python):
import sys


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    v = sum(A)
    for a in A:
        v -= a
        ans += a * v
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

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

ans = 0

for aa in a:
  ans += aa
  ans %= mod
ans *= ans
ans %= mod
for aa in a:
  ans -= aa*aa
  ans %= mod


if ans%2 == 1:
  print((ans+mod)//2)
else:
  ans //= 2
  print(ans)

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

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

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

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

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

MOD = 10**9 + 7


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

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

ans //= 2
ans %= MOD

print(ans)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
sq_s = 0
for i in range(len(arr)):
    sq_s += arr[i]*arr[i]
m = 1000000007
print(((s**2 - sq_s)//2)%m)

Solution (Python):

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

cnt = 0
sumall = sum(A)

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

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

for n, i in enumerate(reversed(A[1:]), 1):
    s += i
    ans += A[N-n-1] * s
    
print(ans % 1000000007)

Solution (Python):

n = int(input())


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

wari = 10**9 + 7

ruiseki = [0]
for i, ai in enumerate(a):
    ruiseki.append(ruiseki[i] + ai)

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

print(ans)

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

ans = 0

for aa in a:
  ans += aa
  ans %= mod
ans *= ans
ans %= mod
for aa in a:
  ans -= aa*aa
  ans %= mod


if ans%2 == 1:
  print((ans+mod)//2)
else:
  ans //= 2
  print(ans)

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

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

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

sum_a = 0
sum_aa = 0
for a in aaa:
  sum_a += a
  sum_aa += a ** 2
  
print(((sum_a ** 2 - sum_aa) // 2) % (10 ** 9 + 7))

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

for ai in A:
    ans+=(ai*(s-ai))
print((ans//2)%(10**9+7))

Solution (Python):
import math
import sys

def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))

def is_prime(n):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True

def swap(a,b):
    temp=a
    a=b
    b=temp
    return a,b

def seive_primes(n):
    flag=[0]*(n+10)
    flag[1]=flag[0]=1
    i=2
    while i*i<=n+1:
        if flag[i]==0:
            j=i*i
            while j<=n+1:
                flag[j]=1
                j+=i
        i+=1
    return flag

def checkRecursive(x, n, curr_num=1, curr_sum=0): 
    results = 0 
    p = curr_num**n 
    while(p + curr_sum < x):  
        results += checkRecursive(x, n, curr_num + 1, p + curr_sum) 
        curr_num = curr_num + 1
        p = curr_num**n  
    if(p + curr_sum == x): 
        results = results + 1
    return results

def findMinSwap(arr, n): 
    vec = [] 
    for i in range(n): 
        vec.append([arr[i], i])  
    vec = sorted(vec) 
    ans, c, j = -1, 0, 0
    for i in range(n):  
        if(vec[i][1] == i): 
            continue
        else:  
            vec[i][0], vec[vec[i][1]][1] = swap(vec[i][0],vec[vec[i][1]][1])
            vec[i][1], vec[vec[i][1]][1] = swap(vec[i][1],vec[vec[i][1]][1]) 
        if(i != vec[i][1]): 
            i -= 1
        ans += 1
    return ans

def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

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

def alphabates():
    return "abcdefghijklmnopqrstuvwxyz"

def binary_search(ls,n,flag):
    low=0
    hi=n-1
    while(low<=hi):
        mid=(low+hi)//2
        if ls[mid]==flag:
            return mid
        elif ls[mid]>flag:
            hi=mid-1
        else:
            low=mid+1
    return -1

def Binary(n):
    if n==0:
        return "00000000"
    binary = "" 
    i = 0
    while n > 0 and i<=8: 
        s1 = str(int(n%2)) 
        binary = binary + s1 
        n /= 2
        i = i+1
        d = binary[::-1] 
    return d

def qdrt(x,a,b,c):
    return a*x*x+b*x+c

def inp():
    ls=list(map(int,input().split()))
    return ls

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

def knapSack(W, wt, val, n): 
    K = [[0 for x in range(W + 1)] for x in range(n + 1)]  
    for i in range(n + 1): 
        for w in range(W + 1): 
            if i == 0 or w == 0: 
                K[i][w] = 0
            elif wt[i-1] <= w: 
                K[i][w] = max(val[i-1]+K[i-1][w-wt[i-1]],  K[i-1][w]) 
            else: 
                K[i][w] = K[i-1][w] 
  
    return K[n][W] 

n=int(input())
ls=inp()
ans=sum(ls)**2
sq=0
for i in range(n):
    sq+=ls[i]**2
print(((ans-sq)//2)%1000000007)

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

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

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

mod = 10**9 + 7

a_sum = sum(a_list)

ans = 0
for i in range(0, n):
    ans += (a_list[i] * (a_sum - a_list[i]))
ans = ans // 2
print(ans % mod)

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

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

ans = 0
mod = 10 ** 9 + 7

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

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
result = sum(A)**2
for i in A:
    result -= i**2
print((result//2)%1000000007)

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

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

s = sum(A)
result = 0

MOD = 10**9 + 7

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

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    
    temp = 0
    a_sum = []

    for i in range(len(a)):
        temp += a[i]
        a_sum.append(temp)

    total = 0
    a_sum.reverse()
    a.reverse()

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

if __name__ == '__main__':
    main()

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

temp=sum(A)
ans=0

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

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

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

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

tmp = 0
li = []
for i in range(n - 1, 0, -1):
    tmp += a[i]
    li.append(tmp * a[i - 1])

print(sum(li) % mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sum_a = a[0]
res = 0
mod = 10 ** 9 + 7

for i in range(1, n):
    res = (res + ((sum_a % mod) * (a[i] % mod)) % mod) % mod
    sum_a = (sum_a + a[i]) % mod

print(res % mod)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
A.sort()
ans = 0
sumA = sum(A)
for i in range(N):
    sumA -= A[i]
    for j in range(i+1,N):
        if A[i] > A[j]:
            continue
        ans += (A[i] * (sumA % MOD)) %MOD
        break

print(ans % MOD)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7

suma = [0]

for aa in a:
    suma.append((suma[-1] + aa)%MOD)

ans = 0
for i, aa in enumerate(a[:-1]):
    ans += (aa % MOD) * ((suma[-1] - suma[i+1])%MOD)
    ans %= MOD
print(ans)

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

n=int(input())

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

B=[A[0]]

for i in range(len(A)-1):
    B.append((B[i]+A[i+1]) % (10**9+7))

ans=0

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

        


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

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

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

e = s * s 

ss = 0
for i in range(n): 
    ss += a[i] * a[i] 
p =  (e - ss) // 2
print(p % (10**9 + 7))

Solution (Python):
from itertools import accumulate

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

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

print(ans)

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

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

sm=0
sumj=sum(a)

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


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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
a_sum = 0
for i in range(len(A)):
    ans += A[i] * a_sum
    a_sum += A[i]
ans = ans % 1000000007
print(ans)

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

sum_mod = 0
for v in A:
    sum_mod += v
    sum_mod %= MOD

ans = 0
for v in A:
    sum_mod -= v
    if sum_mod < 0:
        sum_mod = MOD + sum_mod
    ans += ((v * sum_mod) % MOD)
    ans %= MOD

print(ans)

Solution (Python):
N = int (input ())
A = [int (x) for x in input().split()]
S = sum (A)
X = 0
for i in range (N-1):
  X += A[i]*(S-A[i])
  S -= A[i]
  if X > 10**9+7:
    X = X%(10**9+7)
print (X)

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

mod = 1000000007

sq_line=[i*i for i in line]

s=sum(line)
t=sum(sq_line)

print(((s*s-t)//2)%mod)

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

Solution (Python):



import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

P = 10**9 + 7

def main():
    N = i2n()
    A = i2nn()
    B = [None] * (N - 1)
    B[-1] = A[-1]
    for i in range(2, N):
        B[-i] = (A[-i] + B[-i+1]) % P
    ans = 0
    for i in range(N - 1):
        ans += (A[i] * B[i]) % P
    print(ans % P)
    return

main()

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

sum_value = sum(A)
m = 10**9 + 7

answer = 0
for a in A:
    sum_value -= a
    answer += ((a * sum_value) % m)

print(answer % m)

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

A_2 = 0
for i in A:
    A_2 += i**2
    
ans = ((sum(A)**2 -A_2)//2)%(10**9 + 7)
print(ans)

Solution (Python):
from collections import deque

def main():
    import sys
    input = sys.stdin.readline

    MOD = 1000000007
    n = int(input())
    A = list(map(int, input().split()))
    tmp = sum(A)
    ans = 0
    for i in range(n-1):
        tmp -= A[i]
        ans += A[i]*tmp
    print(ans%MOD)

if __name__ == '__main__':
    main()

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

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

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

K = 1000000007

sumA = 0
for a in A:
    sumA += a
    sumA = sumA
    

sumA2 = (sumA * sumA)

sumAA = 0
for a in A:
    sumAA += a * a
    
    sumAA = sumAA
    

X = (sumA2 - sumAA) // 2 % K

print(X)

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

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

print(ans)

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

square = 0
for i in A:
    square += i*i
ans = ((sum(A)*sum(A) - square) // 2)%(10**9+7)
print(ans)

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

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

mod = pow(10, 9) + 7

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

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

ans %= mod
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def solve():
    MOD = 10**9+7
    N = int(input())
    A_L = tuple(int(x) for x in input().split())
    cum_a_l = [0] * N
    cum_a_l[0] = A_L[0]
    for i in range(1, N):
        cum_a_l[i] = (cum_a_l[i-1] + A_L[i]) % MOD
    ans = 0

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


solve()

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

mod = 10**9 + 7
s = sum(l)
res = 0

while len(l) > 1:
    i = l.pop()
    s -= i
    res += i * (s%mod)
    res %= mod
    
print(res)

Solution (Python):




import sys









MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    a = read_int_list()
    
    ans = 0

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

    print(int(ans % MOD))

if __name__ == '__main__':
    Main()

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

M = 10**9+7

entire = sum(A) % M

ans = 0
s = 0
for a in A:
    entire -= a
    entire %= M
    ans += (a*entire)%M
    ans %= M
print(ans)

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

mod = 10 ** 9 + 7

arr_sum = 0
for i in range(N):
    arr_sum = (arr_sum + A[i]) % mod

arr_sum_square = (arr_sum * arr_sum) % mod

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

ans = arr_sum_square - individual_square_sum
ans = ans * pow(2, mod - 2, mod)
ans %= mod
print(ans)

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
rev = list(reversed(a))
acc = list(accumulate(rev))
ans = 0
for i in range(n-1):
    ans += acc[i]*a[n-2-i]
print(int(ans%(1000000000+7)))

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
inf = 10**9+7
aa = [0]*N

for i in range(N):
  aa[i] = A[i]**2
X = sum(A)**2 - sum(aa)
print((X//2)%inf)

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

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

for i in range(n):
  ret += A[i] * (S[-1]-S[i])
  ret = ret % MOD
print(ret)

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

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

ans = 0
s = 0

mod = 10**9 + 7

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

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

for i in reversed(range(N-1)):
    s = add(s, A[i+1])
    ans = add(ans, mul(A[i], s)) 
    
print(ans)

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

temp = arr_sum * arr_sum  
temp1 = 0

for i in range(0, n, 1): 
    temp1 += arr[i] * arr[i] 
ans=((temp - temp1)//2)%mod
print(ans)

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

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


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

print(ans % mod)