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):
mod=1000000007
n=int(input())
c=list(map(int,input().split()))
m=sum(c)*sum(c)

g=0
for i in range(len(c)):
	g+=c[i]*c[i]

ll=(m-g)//2
ll=ll%mod
print(ll)

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

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

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

S = [0 for _ in range(N+1)]
T = [0 for _ in range(N+1)]
mod = 1000000007

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

print(int(S[N-1] % mod))

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

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

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

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

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

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

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

ans = L[0] * L[1] % D
sub = L[0] + L[1]
for n in range(2,N):
    ans += L[n] * sub
    sub += L[n]
    
print(ans % D)

Solution (Python):
n=int(input())
A=[0]+list(map(int, input().split()))
mod=10**9 + 7
S=sum(A)
ans=0

for i in range(1, n):
    ans+=A[i]*(S-A[i])
    ans%=mod
    S-=A[i]

print(ans)

Solution (Python):
N = int(input())
x = list(map(int, input().split()))
S = sum(x)
def mod(p):
    return p%1000000007
y = 0
for i in range(N):
    y = y + x[i]**2
print(mod((S**2-y)//2))

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

ans = 0
mod = 10 ** 9 + 7
a_r = list(reversed(a))
sumlist = [a_r[0]]
for i in range(1,len(a)):
  sumlist.append(sumlist[-1] + a_r[i])
sumlist.reverse()
sumlist = sumlist[1:]

for i in range(len(sumlist)):
  ans += a[i] * sumlist[i]

print(ans%mod)

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

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

M = int(1e9+7)

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

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

ans //= 2
print(int(ans % M))

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

res = 0
sums = sum(A)
for i in range(len(A)):
  sums = sums - A[i]
  a = A[i]
  res += ((a * sums) % (10 ** 9 + 7))
print(res % (10 ** 9 + 7))

Solution (Python):








import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) 


di = 10**9+7
cum = [0]*(N+1)
for i in range(N)[::-1]:
    cum[i] = (cum[i+1] + a[i])%di

s = 0
for i in range(N):
    s = (s + (a[i]*cum[i+1])%di)%di
    
    
    
print(s)

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

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

result = 0
s = sum(a)
for i in range(len(a)):
    s = (s-a[i])
    result += s % 1000000007 * a[i]
print(result % 1000000007)

Solution (Python):
MOD = 10 ** 9 + 7
 
N = int(input())
a = list(map(int,input().split()))
 
ans = 0
ans = sum(a) * sum(a) % MOD
ans -= sum(map(lambda x:x * x,a)) % MOD
ans %= MOD
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + MOD) // 2)

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

sum_ = sum(li)
result = 0

for i in range(len(li)):
  sum_ -= li[i]
  result += sum_ * li[i]
  
print(result % (10 ** 9 + 7))

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

A_sum_list = [A_list[N-1]]
ans = A_list[N-1]*A_list[N-2]
sum_temp_old = A_list[N-1]

for i in range(N-1, 1, -1):
    sum_temp = sum_temp_old + A_list[i-1]
    sum_temp_old = sum_temp
    ans += (sum_temp * A_list[i-2])


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

Solution (Python):


import sys
import math
from decimal import Decimal, ROUND_DOWN
from collections import deque
from itertools import combinations
import copy

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, ) = [int(e) for e in lines[0].split(' ')]
    a = [int(e) for e in lines[1].split(' ')]


    return (n, a)


def solve(n, a):

   
    total = 0
    m = int(10**9 + 7)
    s = sum(a)
    s_current = 0
    for i in range(n):
        s_current = s_current + a[i]
        total = (total + a[i] * (s - s_current)) % m

    total = total % m


    return total
    


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

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

mod = 10 ** 9 + 7

sumA = sum(A)
S = 0

for x in range(N):
    sumA -= A[x]
    S = (S + A[x] * (sumA)) % mod

print(S)

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


mod = 10**9 + 7

'''
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum += a[i]*a[j]

ans = sum % mod
print(ans)
'''



s = 0
for i in range(N):
    s += a[i]

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

ans = sum % mod
print(ans)

Solution (Python):
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():

    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    sumnation = 0
    def modinv(a, mod=10 ** 9 + 7):
        return pow(a, mod - 2, mod)
    twoinv = modinv(2, mod)
    for i in A:
        sumnation += (i % mod)
        sumnation %= mod

    ans = pow(sumnation, 2, mod)
    for i in A:
        ans -= pow(i, 2, mod)
        while ans < 0:
            ans += mod
    ans *= twoinv
    ans %= mod
    print(ans)


if __name__ == '__main__':
    solve()

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

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

ans = 0
for i, a in enumerate(A):
    
    ans += a * ((cum_A[N] - cum_A[i + 1]) % mod)
    ans %= mod
    
print(ans)

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

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

Solution (Python):
import itertools

n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ini = []
for i in range(n):
    s -= a[i]
    tmp = a[i]*s
    ini.append(tmp)
print(sum(ini)%(10**9+7))

Solution (Python):
a=input()
b=input().split()
N=int(a)
c=[]
ans=0
for i in range(N):
    c.append(int(b[i]))
s=sum(c)
for i in range(N):
    s=s-c[i]
    ans+=c[i]*s
print(ans%1000000007)

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

A = list(map(lambda x: int(x)%MOD, input().split()))
S = []

tmp_s = 0
for A_i in A[::-1]:
    tmp_s += A_i
    S.append(tmp_s%MOD)
S.pop(-1)
S = S[::-1]

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

Solution (Python):
import sys
import numpy as np
import math  
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate 
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache 
INF = 10**9 + 7

def main():
    n = int(input())
    N = list(map(int,input().split()))
    ans = 0
    """
    for i in range(n - 1):
        
        ans += (N[i] * sum(N[i + 1:])) % INF
        ans %= INF
    """
    
    N2 = [pow(i, 2, INF) for i in N]
    N3 = pow(sum(N), 2, INF)
    
    N4 = (N3 - sum(N2))
    if N4 % 2 == 1:
        N4 += INF
    ans = (N4 / 2) % INF
    print(int(ans))
    return 0

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
B = []
s = 0
ans = 0
val = 1000000007

for i in range(N):
    s += A[i]
    B.append(s)

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

print(ans % val)

Solution (Python):
from itertools import accumulate

mod = 10 ** 9 + 7
input()
l = list(map(int, input().split()))
print(sum(a * b % mod for a, b in zip(list(accumulate(l))[:-1], l[1:])) % mod)

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

ans = 0
summ = sum(lst)
summ_sq = summ**2
for i in range(n):
    ans += lst[i]**2

res = (summ_sq-ans)//2
print(res % ((10**9)+7))

Solution (Python):
m = 1000000000+7


def findProductSum(A, n):

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

    array_sum_square = (array_sum * array_sum) % m

    individual_square_sum = 0
    for i in range(0, n, 1):
        individual_square_sum = (individual_square_sum + (A[i] * A[i]) % m)%m

    aaa=(array_sum_square-individual_square_sum+m)%m
    inv=pow(2,m-2,m)
    anss=aaa*inv

    return anss


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

print(int(int(findProductSum(A, n)) % m))

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

mod = 1000000007

AS = sum(A)
S = [AS]
tmp = 0
for i in range(N):
    tmp += A[i]
    S.append(AS - tmp)

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

print(ans%mod)

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

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

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



ans = 0
for i in range(n):
  ans = ans + sum*a[i]
  ans = ans - a[i]*a[i]
ans = ans//2%m

print(ans)

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

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

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

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


MOD = 10 ** 9 + 7

rev = []

i = 0
for _ in range(n)[::-1]:
    i += lst[_]
    i %=  MOD
    rev.append(i)
    
lst= lst[0:n-1]
rev = rev[0:n-1]

ans = 0
for _ in range(n-1):
    ans += lst[_] * rev[n-(_+2)]
    ans %= MOD
    
print(ans)

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
B = A[::-1]

B = list(accumulate(B))

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

print(ans)

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

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

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

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

Solution (Python):
import numpy as np
def main():
    MOD = 10**9 + 7
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype="i4")

    A = A % MOD
    rsumA = np.cumsum(A[::-1]) % MOD
    count = 0
    for i in range(len(A)-1):
        a = A[i]
        other = rsumA[len(A) - i - 2]
        count += (a * other) % MOD
    count %= MOD
    print(count)





if __name__ == '__main__':
    main()

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

Solution (Python):

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

first = a[0]

ans = first*a[1]

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

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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    tasi = sum(a)
    num = 10**9+7
    ans = 0
    
    for i in range(n):
        tasi -= a[i]
        tasi %= num
        ans += a[i]*tasi
        ans %= num

    print(ans)
main()

Solution (Python):
N = int(input())
l = list(map(int, input().split()))
import itertools

total = sum(l)
cumsum = list(itertools.accumulate(l))

i = 0
sig = 0
for cus in cumsum:
    rest = (total - cus)
    
    sig += (l[i] * rest)
    i +=1
    
    
print(sig % (10**9 + 7))

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

ans = 0
current = 0
for j in range(N):

    if j != 0:
        current += A[j - 1]

    ans += A[j] * current

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

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

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

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

cum = [0] * n
cum[-1] = a[-1]

mod = 10 ** 9 + 7

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

ans = 0

for i in range(1, n):
    num = a[i - 1] * cum[i]
    num %= mod
    ans += num
    ans %= mod

print(ans)

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

sum_a = 0
sum_i = sum(a)

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

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

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

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

part_of_sum=[]
s=0
mini_sum=sum(li[1:])
for j in range(n-1):
  s+=li[j]*mini_sum
  mini_sum-=li[j+1]

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

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

def main():
    n = int(stdin.readline().rstrip())
    ls = list(map(int, stdin.readline().split()))
    ans = 0
    m = 10**9 + 7
    sum1 = sum(ls)%m
    for i in range(n-1):
        sum1 = sum1-ls[i]
        ans = ((sum1 * ls[i])+ans) % m
    print(ans)

if __name__ == '__main__':
    main()

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


if '__main__' == __name__:
    resolve()

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

s = 0
a = 0
for _a in A:
  s += _a * a
  a = (a + _a) % mod
print(s % mod)

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

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

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

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

Solution (Python):
D = int(1e9 + 7)
N = int(input())
M = [int(i) for i in input().split()]

R = sum(M[1:])

sum_ = 0
for i, x in enumerate(M[:-1]):
    sum_ += R * x
    sum_ %= D
    R -= M[i+1]

print(sum_)

Solution (Python):
n=int(input())
s=input()
p=list(s.split())
s1=0
s2=0
for i in range(0,n):
  s1=s1+int(p[i])
  s2=s2+(int(p[i])*int(p[i]))
k= ((s1**2)-s2)//2
k=k%1000000007
print(k)

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 += a[i] *(sum_)
    res = ans % (10**9 + 7)
print(res)

Solution (Python):


MOD = 1000000000 + 7

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

ret = 0
for a in A:
    s -= a
    ret += a * s
    ret %= MOD

print(ret)

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

MOD = 10 ** 9 + 7
total = 0
s = sum(a)

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

print((total // 2) % MOD)

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

Solution (Python):
import numpy
N = int(input())
A = list(map(int, input().split()))
A_sum = numpy.cumsum(A)
ans = 0
for idx in range(len(A)):
    ans += A[idx] * int(A_sum[-1]-A_sum[idx])
print(ans % (10**9+7))

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    n = int(input())
    A = list(map(int, input().split()))

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


if __name__ == '__main__':
    main()

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

Acum = list(accumulate(A))
ans = 0
for i, a in enumerate(reversed(A[1:])):
    ans += Acum[n-i-2]*a
    ans %= MOD


print(ans)

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

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

Solution (Python):
n=int(input())
z=[int(x) for x in input().split(' ')]
s=sum(z)
md=1000000007
ans=0
for i in range(n):
    s-=z[i]
    ans+=s*z[i]
print(ans%md)

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

Solution (Python):
def sumproductsofpairs(lst):
    total = 0
    psum = 0
    for x in lst:
        total = (total + (psum * x)%mod)%mod
        psum = ((psum)%mod + (x)%mod)%mod
    return total


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

mod=10**9+7
print(sumproductsofpairs(array)%mod)

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

cnt=A[-1]
sumA=[cnt]
for i in range(N-2,0,-1):
  sumA.append(sumA[-1]+A[i])

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

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

    sum_A = [0] + [0 for i in range(N + 1)]

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

    A = [0] + A
    ans = 0

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

    print(ans % (10**9 + 7))
    
if __name__ == "__main__":
    main()

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


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


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


MOD = 10 ** 9 + 7


def main():
    N = II()
    target = LI()

    ans = 0
    sums = [0] * N
    sum_all = target[0]
    sums[0] = target[0]
    for i in range(1, N):
        sum_all += target[i] % MOD
        sums[i] = sums[i-1] + target[i]

    for i in range(N):
        ans += target[i] * (sum_all - sums[i])
        ans = ans % MOD

    print(ans)


main()

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

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

a = A[::-1]
s = [0]*(n+1)

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

s = s[:n]
s = s[::-1]

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

Solution (Python):
mod = 1000000007
N = int(input())
A = list(map(int,input().split()))
sum_a = sum(A)
ans = 0
for a in A:
    ans += a*(sum_a-a)
    
ans //= 2

print(ans%mod)

Solution (Python):
n=int(input())
l=input().split()
li=[int(i) for i in l]
sumi=0
for i in li:
    sumi+=i
sum2=0
for i in li:
    sum2+=(i*i)
sumi=sumi*sumi
z=(sumi-sum2)//2
print(z%1000000007)

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

Solution (Python):
N = int(input())
ls = list(map(int, input().split()))
m = 1000000007
sumNum = sum(ls)
currentSum, lastAns = 0, 0
for i in range(N -1):
    currentSum += ls[i]
    lastAns = (lastAns + (ls[i] * (sumNum - currentSum))) % m
print(lastAns)

Solution (Python):
import math
import sys,collections
from sys import stdin, stdout  


def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip() 
def input(): return sys.stdin.readline().strip()

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 
def is_subsequence(x, y):
    """Test whether x is a subsequence of y"""
    x = list(x)
    for letter in y:
        if x and x[0] == letter:
            x.pop(0)

    return not x    
def sieve(): 
	spf[1] = 1
	for i in range(2, MAXN): 
		spf[i] = i 
	for i in range(4, MAXN, 2): 
		spf[i] = 2

	for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
		if (spf[i] == i): 
			for j in range(i * i, MAXN, i): 
				if (spf[j] == j): 
					spf[j] = i 
def getFactorization(x): 
	ret = list() 
	while (x != 1): 
		ret.append(spf[x]) 
		x = x // spf[x] 

	return ret 
def getFloor(A, x):

    (left, right) = (0, len(A) - 1)

    ind,floor = -1,-1
    while left <= right:
        mid = (left + right) // 2
        '''if A[mid] == x:
            return mid'''
        if x < A[mid]:
            right = mid - 1
        else:
            floor = A[mid]
            ind=mid
            left = mid + 1
            
    return ind
def check(st) : 
  
    
    n = len(st) 
    digitSum = 0
      
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i]) 
  
    
    
    return (digitSum % 9 == 0)     
def isPowerOfTwo(n): 
    if (n == 0): 
        return False
    while (n != 1): 
            if (n % 2 != 0): 
                return False
            n = n // 2
            
              
    return True
def kitte(n):
	c=0
	while(n!=0):
		n=n//2
		c+=1
	return c	
def aa(b,c):
	m=min(b,c)
	b-=m
	c-=m
	if(c>0 and b>0):
		return(m+((b+c)//3))
	else:
		return(m)
def bb(a,c):
	m=min(a,c)
	a-=m
	c-=m
	if(c>0 and a>0):
		return(m+((a+c)//3))
	else:
		return(m)
def cc(b,a):
	m=min(b,a)
	b-=m
	a-=m
	if(a>0 and b>0):
		return(m+((b+a)//3))
	else:
		return(m)		
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		


mod=(10**9)+7	
def main():
		n=int(input())
		l=get_array()
		s=0
		s=findProductSum(l,n)
		print(s%mod)		

	



	

	
			


		




		






		







			



	

	




	





















	




















		
			


		

			

		





			

	























				

	















	

	










if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, permutations, combinations, accumulate
from bisect import bisect_left, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor


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


def input_int():
    return int(input())


N = int(input())
A_LI = input_list()
A_ACC = list(accumulate(A_LI))
MOD = 10 ** 9 + 7
ans = 0
for i in range(1, N):
    ans += A_LI[i] * A_ACC[i - 1]
print(ans % MOD)

Solution (Python):
n=int(input())
alist=list(map(int,input().split()))
MOD=10**9+7
nijo=0
for i in range(n):
    nijo+=(alist[i]**2)
gokei=sum(alist)

ans=(gokei**2-nijo)
ans=ans//2
ans=ans%MOD
print(ans)

Solution (Python):





def lg(value):
    flag = False
    
    if flag:
        print(str(value))



def xt(log):
    lg('★exit() - ' + str(log))
    exit()



def get_results():

    
    lines = list()
    
    lines_count = 2
    
    
    
    
    
    for _ in range(lines_count):
        lines.append(input())

    
    
    N = int(lines[0])
    
    values = list(map(int, lines[1].split()))
    
    
    
    
    
    
    

    lg(f'values=[{values}]')

    targets = list()
    
    su = 0
    for j in range(1, N):
        
        
        su += values[N - j]
        targets.append(su)

    su = 0
    for i in range(N-1):
        
        
        su = (su + values[i] * targets[N-2-i]) % (10**9+7)

    return [su]



def main():
    results = get_results()

    for result in results:
        print(result)



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
v = [int(x) for x in input().split()]
suma, ans = sum(v), 0
for i in range(n - 1):
    suma -= v[i];
    ans += (suma * v[i])
print(ans % 1000000007)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import math

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

n = readInt()
a = readInts()

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

ans = 0

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


print(ans)

Solution (Python):



N = int(input())
A_list = list(map(int, input().split()))
ans = 0
SUM = sum(A_list)
for i in range(N):
    SUM -= A_list[i]
    if i != N -1:
        ans += A_list[i] * SUM
while ans >= 10 ** 21 + 7000000000000:
    ans -= 10 ** 21 + 7000000000000
while ans >= 10 ** 19 + 70000000000:
    ans -= 10 ** 19 + 70000000000
while ans >= 10 ** 17 + 700000000:
    ans -= 10 ** 17 + 700000000
while ans >= 10 ** 15 + 7000000:
    ans -= 10 ** 15 + 7000000
while ans >= 10 ** 13 + 70000:
    ans -= 10 ** 13 + 70000
while ans >= 10 ** 11 + 700:
    ans -= 10 ** 11 + 700
while ans >= 10 ** 9 + 7:
    ans -= 10 ** 9 + 7
print(ans)

Solution (Python):
from sys import stdin
import itertools

def main():

    input = stdin.readline

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

    mod = (10 ** 9) +7

    ans = 0

    total = sum(A)

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):



import collections
import sys
import copy
import re
import math


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


def main():
    N = I()
    AArray = LI()
    MOD = 1000000007
    aSum = sum(AArray)
    nowAsum = 0
    ans = 0

    for i in range(N-1):
        a = AArray[i]
        nowAsum += a
        asum = aSum-nowAsum
        asum %= MOD
        ans += a*asum % MOD
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


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

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

Solution (Python):
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))
mod = 10**9 + 7

n = ri()
a = rl()
s = sum(a)
ans = 0
for i in a:
    s -= i
    ans = (ans + s*i)%mod
print(ans)

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



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



for i in range(n):
    ai = A[i]
    ans = (ans + ai*(sum_a[-1] - sum_a[i+1])) % MOD
    




ans = (ans + MOD) % MOD
print(ans)

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

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

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

arr.reverse()
ans = 0
for i in range(len(a)-1):
    
    ans += (a[i] * (arr[i]-a[i]))%MOD
   
print(ans%MOD)

Solution (Python):
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    m = 1000000007
    ans = 0
    ss = sum(a[1:])
    for i in range(n-1):
        ans += a[i]*ss
        ss -= a[i+1]
        ans %= m
    print(ans)

main()

Solution (Python):
import numpy as np
MOD = 10**9+7
n = input()
a = list(map(int, input().split()))
ans = 0
cum_a = np.cumsum(a[::-1])
cum_a = cum_a[::-1]
for i, ai in enumerate(a):
  if i == len(a)-1:
    continue
  sum_aj = cum_a[i+1]
  ans += ((ai%MOD)*(sum_aj%MOD))%MOD

print(ans%MOD)

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