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

def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

    sum_A = sum(A) % mod
    ans = 0
    for a in A:
        sum_A -= a
        if sum_A < 0:
            sum_A += mod
        ans += a * sum_A
        ans %= mod
    print(ans % mod)


if __name__ == '__main__':
    main()

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

Solution (Python):
nn = int(input())
aa = list(map(int, input().split()))
bb = [0]*(nn-1)
mysum = 0
for i in range(nn):
    mysum += aa[i] % (10**9 + 7)
mydiff = 0

for i in range(1,nn):
    mydiff += aa[i - 1]
    tete = mysum - mydiff
    if tete >= 0:
        bb[i-1] = tete
    else:
        bb[i-1] = tete + 10**9+7

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

print(finalsum)

Solution (Python):
import numpy as np

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

A = np.array(A)
MOD = 10**9 + 7

ruisekiwa = np.zeros(N, dtype='int')
for i in range(1, N):
    ruisekiwa[i] = ruisekiwa[i-1] + A[i]

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

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

S = sum(A)
S2 = sum(map(lambda x: x * x, A))

print((S*S-S2)//2 % 1000000007)

Solution (Python):
import numpy as np

N=int(input())
A=np.array(input().split(" "),dtype=np.int64)

mod=1000000007


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

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

print(ans)

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

    mod = 10**9 + 7
    answer = 0
    sum_a = sum(a) % mod

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

    print(answer)


'''
    for i in range(n):
        sum_sub = 0
        for j in range(i+1, n):
            sum_sub += a[j]
            if sum_sub >= mod:
                sum_sub %= mod
        answer += a[i] * sum_sub
        if answer >= mod:
            answer %= mod
    print(answer)
'''

'''
    for i in range(n):
        for j in range(i+1, n):
            answer += a[i] * a[j]
            if answer >= mod:
                answer %= mod
    print(answer)
'''

if __name__ == "__main__":
    main()

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

ans = x**2 -y
print((ans//2)%(10**9+7))

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

mod = 10**9+7

s = sum(lis)
tmp = 0
for i in lis:
    tmp += i**2

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

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

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

sums *= sums;
ans = sums;

for i in range(n):
    ans -= a[i]*a[i]
ans //= 2
ans %= 1000000007
print(int(ans))

Solution (Python):
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

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

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

sum = 0
row = 0
for ii in range(N-1):
    i = N-2-ii
    row += A[i+1]
    row %= mod
    sum += A[i] * row
    sum %= mod

print(sum)

Solution (Python):
from itertools import accumulate
mod = 10**9 +7

def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans =0
    ac = list(accumulate(a))

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

if __name__ == '__main__':
    main()

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

for i in range(1,nn):
    mydiff += aa[i - 1]
    tete = mysum - mydiff
    if tete >= 0:
        bb[i-1] = tete
    else:
        bb[i-1] = tete + 10**9+7

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

print(finalsum)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    cumsum_a = [0] * len(a)
    cumsum_a[0] = a[0]
    for i in range(1, len(a)):
        cumsum_a[i] += cumsum_a[i-1] + a[i]

    sum_val = 0
    num = 10 ** 9 + 7
    for i in range(0, n - 1):
        sum_val += a[i] * (cumsum_a[-1] - cumsum_a[i])
        if sum_val > num:
            sum_val %= num
    print(sum_val)

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

res=0
sum_a=sum(a)
b=0
t=0
for i in range(0,len(a)-1) :
    t=a[i]
    b+=a[i]
    res+=(sum_a-b)*t%(10**9+7)

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

Solution (Python):
n = int(input())
n_list = [int(i) for i in input().split()]

s = sum(a**2 for a in n_list)
ans = sum(n_list) ** 2 - s

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

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

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

	sum_h = sum(h)%(10**9 + 7)
	ans = 0
	for i in h:
		i = i%(10**9 + 7)
		sum_h -= i
		ans += i*sum_h

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

	

if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
 
sum = 0
sum1 = 0
mod = 1000000000+7
for i in range(n):
    if a[i] >= mod:
        a[i] = a[i] % mod
    sum1 += a[i]
    sum1 %= mod
    
for i in range(n-1):
    
    sum1 -= a[i]
    
    if sum1 < 0:
        sum1 += mod
    sum += a[i] * sum1
    sum %= mod
            
print(sum)

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

suma = sum(a)**2
sums = 0
for i in range(n):
    sums += a[i]*a[i]

ans = (suma - sums) // 2
ans %= 1000000007

print(int(ans))

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

print(_sum)

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

MOD = 1000000007

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

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

for i in range(0,N-1):

    ans=(ans+wa[i]*A[i])%(10**9+7)
print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
k = 0
num = sum(a)
t = 10 ** 9 + 7

for i in a:
    num -= i
    k += num * i

ans = k % t
print(ans)

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

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

ans = ((sum(a))**2 - sum_sq_a) // 2

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

Solution (Python):
N = int(input())
An = list(map(int, input().split()))
tt = sum(An)
total = tt
ans = 0
for A in An:
    At = A * (total-A)






    ans = (ans+At) % (10**9+7)
    total -= A

print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
mod = 10 ** 9 + 7
ans = 0

'''
for i in range(N - 1):
  for j in range(i+1, N):
    a = A[i] % mod
    b = A[j] % mod
    ans += (a * b) % mod
    ans = ans % mod
'''
tot = 0
for i in range(N):
  A[i] %= mod
  tot += A[i]
  tot %= mod
for i in range(N-1):
  tot -= A[i]
  ans += (A[i] * tot) % mod
  ans %= mod
print(ans)

Solution (Python):








    






mod = int(1e9+7)

INF = 1<<50

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

def main():
    n = int(input())
    a = readInt()
    c_sum = [0]
    for i in range(n):
        c_sum.append(c_sum[i]+a[i])
    ans = 0
    for i in range(n-1):
        ans += a[i] * (c_sum[-1] - c_sum[i+1])
        ans %= mod
    print(ans)
    return

if __name__=='__main__':
    main()

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

a = 0
for i in reversed(A):
    a += i
    l.append(a)
l.pop(n-1)
ans = 0

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

Solution (Python):
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7))
solve()

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
sum = 0
ans = 0

for e in a:
  sum += e
  
for e in a:
  sum -= e
  ans += e*sum

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

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

res = 0
sum_a = sum(a)
b = 0
t = 0
for i in range(0, len(a)-1):
  t = a[i]
  b += a[i]
  res += (sum_a - b)*t%(10**9 + 7)
print(res%(10**9 + 7))

Solution (Python):
def calc(A, N, i):
    ans = 0
    ai = A[i]
    for i in range(i, N - 1):
        aj = A[i + 1]
        ans += ai * aj
    return (ans)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = [0] * (N + 1)
    for i in range(0, N - 1):
        if A[i] != 0:
            ans[i] = calc(A, N, i)
            break
    for j in range(i + 1, N - 1):
        if A[j] != 0:
            ans[j] = (ans[j - 1] - A[j - 1] * A[j]) // A[j - 1] * A[j]
        else:
            ans[j] = 0
    ret = 0
    for k in range(0, N):
        ret += ans[k]
    ret = ret % mod_v
    print(ret)


if __name__ == '__main__':
    main()

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

    sum_tail = sum(A)

    total = 0
    for idx, i in enumerate(A):
        sum_tail -= A[idx]
        if idx + 1 == len(A):
            break
        total += i * sum_tail
    print(total % (10**9 + 7))


def main():
    probC()


if __name__ == '__main__':
    main()

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

num_sum = 0
temp_sum_num = sum(A)

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


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

print(num_sum)

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

s_list = [0]*(n+1)
for i,a in enumerate(a_list):
    s_list[i+1] = s_list[i]+a


ans = 0
for i,a in enumerate(a_list):
    ans += a * (s_list[n]-s_list[i+1])
    
print(ans%mod)

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

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

print(z%1000000007)

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

mod = 10**9+7

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

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

ans = all - di
ans *= (mod + 1) // 2
ans %= mod

print(ans)

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

prod=0

law=10**9+7

sumation=sum(S)

for i in range(N):
  sumation=sumation-S[i]
  prod=prod+(S[i]*sumation)%law

print(prod%law)

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

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

print(ans % mod)

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

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

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):
import itertools
x = 10**9 + 7
n = int(input())
a = list(map(lambda i: i % x , map(int, input().split(" "))))
sum_a = []
prev = 0
for i in a:
    sum_a.append(prev + i)
    prev = prev + i

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

Solution (Python):
import sys
 
stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))
 
 
def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) // 2
    print(int(ans % mod))
 
 
if __name__ == '__main__':
    main()

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

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

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


q=deque(A)

ans=0
sums=sum(q)

for i in range(N-1):
    qwe=q.popleft()
    ans+=qwe *(sums-qwe)
    sums-=qwe
print(ans%(10**9+7))

Solution (Python):
modulo=10**9+7
N=int(input())
array=[(int(x))%modulo for x in input().split()]
total=((sum(array))**2)%modulo
for i in array:
    total=((total-((i%modulo)**2)))%modulo
print((total*(5*10**8+4))%modulo)

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

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

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

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

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

sigma = 0
after = sum(a[0:])
for i in range(len(a)-1):
  start = a[i]
  after = after - a[i]
  sigma = sigma + start * after
  if sigma >= (10**9 + 7):
    sigma = sigma % (10**9+7)

print(sigma)

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

mod = 1000000000 + 7
ans = 0

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

ans %= mod
print(ans)

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

Solution (Python):
from sys import stdin
import itertools
def main():
    number = int(input())
    num_list = list(map(int, stdin.readline().split()))
    num_list_sum = sum(num_list)
    total = 0
    for i in range(number):
        num_list_sum -= num_list[i]
        total += num_list[i] * num_list_sum
    print(total % (10**9+7))
if __name__ == '__main__':
    main()

Solution (Python):
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) // 2
    print(int(ans % mod))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007
x = sum(A)
ans = 0
 
for i in range(N):
  x -= A[i]
  y = x % MOD
  z = (A[i] * y) % MOD
  ans += z
  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 A:
    sum_a+=i
    sum_a%=mod

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

Solution (Python):
import functools
import operator

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

Solution (Python):
MOD = 1000000007

n = int(input())
str_ary = input().split()
ary = [int(c) for c in str_ary]









result = 0
sum = sum(ary[i] for i in range(n))




for i in range(n):
  sum -= ary[i]
  result += ary[i] * sum

print(result % MOD)

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

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

print(ans%mod)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


N = I()
A = LI()
mod = 10**9+7

ans = sum(A)**2-sum(A[i]**2 for i in range(N))
ans %= mod
ans *= pow(2,mod-2,mod)
ans %= mod
print(ans)

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

ans = 0
sum_A = sum(A_int_list)

for i in range(len(A_int_list)):
    sum_A -= A_int_list[i]
    ans += A_int_list[i] * sum_A


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

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    s = sum(A)
    t = sum(a * a for a in A)
    print((s ** 2 - t) * pow(2, MOD - 2, MOD) % MOD)
resolve()

Solution (Python):

"""
Created on Sat Aug 29 22:19:15 2020

@author: naoki
"""

N = int(input())

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

count1 = 0
count2 = 0
count = 10**9 +7
for i in A:
    count1+=i

for j in A:
    count2 = (j*(count1-j) + count2)%count
    count1 = count1 -j 
    
print(count2%count)

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

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

if __name__ == "__main__":
    solve()

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

for a in A:
    tmp -= a
    sum_ += a * tmp

print(sum_ % (1_000_000_007))

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

z = 0
for i in range(n):
    z += a[i]
e = z % 2

y = (z ** 2) % 2000000014

x = 0
for j in range(n):
    x += a[j] ** 2
    x = x % 2000000014

w = int(((y - x) / 2) % 1000000007)
print(w)

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

Ans=0
S=[0]*(len(A)+1)

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

  
for i in range(0,N):

  Ans+=A[i]*(S[N]-S[i+1])
  
print(Ans%(10**9+7))

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




ret = 0
now_sum = sum(A_list)


for i in range(len(A_list)):
  now_sum -= A_list[i]
  multiple_base = A_list[i]
  
  before_total = 0
  
  ret += multiple_base * now_sum
  
print(ret % 1000000007)

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



mod = (10**9)+7
ans = 0
c = [0]*n
c[n-1] = a[n-1]
for i in range(n-1,1,-1) :
    c[i-1] = c[i]+a[i-1]
c.pop(0)
for i in range(0,n-1) :
    ans += (a[i]*c[i])

print(ans%mod)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
s = 0
t = 0
b = 0
m = 10 ** 9 + 7
for i in range(n):
    t += a[i]
    t = t % m
    b += a[i] ** 2
    b = b % m
s += int(((((t ** 2) % m + m - b) % m) * (5 * 10 ** 8 + 4)) % m)
print(s)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
i = 0
tmp = 0
tmpura = 0
while(i < n):
    tmp += a[i]
    i+=1
tmp=tmp **2
i = 0
while (i < n):
    tmpura += a[i]**2
    i+=1
tmpura=tmpura
ans = ((tmp - tmpura)//2)%(10**9+7)
print(ans)

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

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

check = ans
for i in range(1, n):
    if li[i-1] == 0:
        continue
    check -= li[i] * li[i-1]
    check //= li[i-1]
    check *= li[i]
    ans += check
    ans %= mod

print(ans)

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

DIV = 10**9+7
ans = 0
Asum = sum(A)
Asum_sq = Asum**2

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

res = (Asum_sq-ans)//2
print(res%DIV)

Solution (Python):
mod = 1000000000+7

def product(N, As):
  result = 0
  summer = sum(As)
  for i in range(N-1):
    left = As[i]
    summer = summer - left
    result += left * summer
    
  return result % mod


if __name__ == "__main__":
  N = list(map(int, input().split()))
  As = list(map(int, input().split()))
  print(product(N[0], As))

Solution (Python):
from collections import deque
import sys, copy, itertools,heapq
input = sys.stdin.readline
 
n = int(input())
A = list(map(int,input().split()))
 
suma = sum(A)
a = (suma ** 2)
 
b =0
for i in range(n):
  b += A[i]**2
 
ans = (a-b)//2
 
answer = ans % (10**9 +7)
 



print(answer)

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

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)


ans = 0
for i in range(n-1):


    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

Solution (Python):
from sys import exit, stdin

input = stdin.readline
import copy


import numpy as np

nmod = 1000000007

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

ans = 0
tsum = 0
for i in range(N - 1, 0, -1):
    tsum += A[i]
    tsum %= nmod
    tmp = (A[i - 1] * tsum) % nmod
    ans += tmp
    ans %= nmod

print(int(ans))

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

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

print(s)

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

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

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

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

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

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

Solution (Python):
N = int(input())
A = map(int,input().split())
ans = 0
ans2 = 0
mod = 10 ** 9 + 7
for a in A:
    ans += a
    ans2 += a**2

print(((ans **2 - ans2)//2)%mod)

Solution (Python):
import itertools
N = int(input())
A =  list(map(int, input().split()))
sa = sum(A)
r = 0
xx = sa
m = 10**9+7
for x in A:
    xx -= x
    r += x*xx
    r = r % m
print(r)

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

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

if __name__ == "__main__":
    resolve()

Solution (Python):
import itertools as itr
MOD=pow(10,9)+7

N=int(input())

A=list(map(int, input().split()))
sumA = list(itr.accumulate(A))
ans=0
for i in range(len(A)-1):
    a=A[i+1]
    b=sumA[i]
    ans=(ans+a*b%MOD)%MOD

print(ans)

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

def calc(A, n, dp):
    dp += [A[0] * A[1]]
    rsum = A[0] + A[1]
    for i in range(2, n):
        dp += [dp[-1] + rsum * A[i]]
        rsum += A[i]

    i = dp.index(max(dp))
    rsum = 0
    for j in range(i + 1):
        rsum += A[j]
    res = max(dp)
    dp2 = max(dp)
    for j in range(0, i):
        rsum -= A[j]
        dp2 -= A[j] * rsum
        res = max(dp2, res)
    return res

ans = calc(a, n, dp) % mod
print(ans)

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

pref = [0]*n

for i in range(n)[::-1]:
    pref[i] = (pref[i + 1] if i < n - 1 else 0) + nums[i]
    pref[i] %= MOD

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

print(ans)

Solution (Python):

def Sum(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())
a=[int(i) for i in input().split()]
print(Sum(a,n)%(10**9+7))

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

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

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

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
def calc_mod(n):
    return n %(10**9+7)
AA=list(map(calc_mod, A))
X=0
XX=0
for i in range(N-1):
  XX+=AA[N-i-1]
  X+=AA[N-i-2]*XX
  X=X%(10**9+7)
print(X)

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7


def main():
    ans = 0
    cs = np.cumsum(np.array(a))
    for i in range(n-1):
        s = (cs[-1] - cs[i]) % mod
        ans = (ans+(a[i]*int(s)) % mod) % mod
    return ans


n, *a = map(int, read().split())
a = main()
print(a)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
t=10**9+7
S=[a%t for a in A]
g=sum(S)

ans=0
for i in range(N):
       g-=S[i]
       ans+=S[i]*g%t
print(ans%t)

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

if __name__ == '__main__':
    main()

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

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

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

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


def mod10_9_7(num):
    return num % (10**9+7)


seki = A[-1]

ans = 0
for i in range(N-2, -1, -1):
    ans += A[i] * seki
    seki += A[i]
print(mod10_9_7(ans))

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

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

max = (10 ** 9) + 7


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


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

sum = ((wa*wa) - rem) // 2

ans = sum % max

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
n = len(A)
z = 10 ** 9 + 7
ans = 0

x = sum(A)
x = x ** 2
for i in A:
    y = i * i
    x -= y

x = x // 2
x = x % z
print(x)

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

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

d = 1000000000 + 7

s = 0

sum_list = [A[0]]
for a in A[1:]:
    sum_list.append(a + sum_list[-1])
for i in range(N):
    s += A[i] * (sum_list[N-1] - sum_list[i])
print(s % d)

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

sumA = sum(A)

ans = 0

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

print(ans % 1000000007)

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

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)