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():
    N = int(input())
    A = list(map(int, input().split()))
    all_sum = sum(A) ** 2
    st = 0
    for i in range(N):
        st += A[i] ** 2
    print(int(((all_sum - st)//2) % 1000000007))
main()

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

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

sum_A = sum(A)
ans = 0
for a in A[:-1]:
  sum_A -= a
  ans += a * sum_A

ans %= mod
print(ans)

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

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

a = a ** 2
k = (a-b) // 2 % (10 ** 9 + 7)

print(k)

Solution (Python):
a=s=0
for x in[*open(0)][1].split():x=int(x);a+=s*x;s+=x
print(a%(10**9+7))

Solution (Python):
from functools import reduce
mod = 10**9 + 7

n = int(input())
arr = list(map(int, input().split()))
to_mutiply = [0]*n

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

data = list(map(lambda i: (to_mutiply[i]*arr[i]) % mod, range(n-1)))
print(reduce(lambda x, y: (x+y) % mod, data))

Solution (Python):
a=s=0
for x in map(int,[*open(0)][1].split()):a+=s*x;s+=x
print(a%(10**9+7))

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

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

print(ans)

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

sum = 0
f = 0

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

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

cumsum = []
total = 0
for num in a:
    total+=num
    cumsum.append(total)

result = 0
MOD = pow(10,9)+7
for i,num in enumerate(cumsum):
    temp = total-num
    result += temp*a[i]
    
print(result%MOD)

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


mod = 10**9 + 7
s = 0
t = 0
for i in range(N):
    s += A[i]
    s %= mod
    t += (A[i]**2 % mod)
    t %= mod
s = s**2 % mod
ans = (s - t) % mod

ans = (ans * 500000004) % mod

print(ans)

Solution (Python):
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    csum = [0]
    csum.extend(accumulate(A))

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

n = int(input())
num_list = input().split()

mod_base = 10 ** 9 + 7

num_list = [int(x) for x in num_list]

sum_list = []
sum_tmp = sum(num_list)
for i in range(len(num_list)):
    sum_list.append(sum_tmp)
    sum_tmp -= num_list[i]

all_sum = 0
for index, num in enumerate(num_list):
    if index + 1 >= len(num_list):
        break
    all_sum += num * sum_list[index+1]

print(all_sum % mod_base)

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

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


ans = (s-t) % (10**9+7)

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

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

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

ans = (s-t) % (10**9+7)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s2=int(sum(a)*sum(a))
a2=[int(i*i) for i in a]

gyakugen=pow(2,10**9+5,10**9+7)
ans1=(s2-sum(a2))*gyakugen
print(int(ans1%(10**9+7)))

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

N, *A = map(int, open(0).read().split())

S1 = sum(A)
S2 = sum(a * a for a in A)

print((S1 ** 2 - S2) // 2 % mod)

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

sum=0
f=0

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

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

Solution (Python):
try:
    n=int(input())
    m=10**9+7
    arr=[int(i) for i in input().split()]
    sm=sum(arr)%m
    ans=0
    for i in range(n-1):
        sm-=arr[i]
        x=arr[i]*sm
        ans+=x
        
    print(ans%m)
except  EOFError as e:
    print(e)

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

B = []
tmp = 0
for i in range(n):
    tmp += A[n-i-1]
    tmp %= mod
    B.append(tmp)

sum = 0
for i in range(n-1):
    sum += A[i]*B[n-i-2]
    sum %= mod
print(sum)

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

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

mod = 10**9+7

x = (((sum(A))**2) // 2)
x -= (sum([a**2 for a in A]) // 2)
x %= mod
print(x)

Solution (Python):
n=int (input())
a= list(map(int,input().split()))
s2=int(sum(a)*sum(a))
a2=[int(i*i) for i in a]
ans1=(s2-sum(a2))//2

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

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):
def resolve():
    import sys
    input = sys.stdin.readline
 
    n = input().rstrip()
    past_a = 0
 
    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        
        ans += a * past_a
        
        past_a += a
        
 
    x = 1000000007
 
    ans = ans % x
 
    print(ans)
 
if __name__ == "__main__":
    resolve()

Solution (Python):

if __name__ == "__main__":
	MOD = 10 ** 9 + 7
	N=int(input())
	A=list(map(int,input().split()))

	Asum = sum(A) % MOD

	ans = 0
	for n in range(N-1):
		Asum -= A[n]
		ans += ((A[n] * Asum) % MOD)

	print(ans % MOD)

Solution (Python):
import math

class BitIndexedTree:
	'''NOTES: 1-origin-indexed
	'''
	def __init__(self, itemCount):
		self.itemCount = itemCount
		self.items = [0 for i in range(itemCount+1)]

	def add(self, i,value):
		while i <= self.itemCount:
			self.items[i] += value
			i += (i & (-i))

	def sumFromStart(self, end):
		summary = 0
		i = end
		while i > 0:
			summary += self.items[i]
			i -= (i & (-i))
		return summary

	def sum(self, start,end):
		summary = self.sumFromStart(end) - self.sumFromStart(start-1)
		return summary

if __name__ == "__main__":
	MOD = 10 ** 9 + 7
	N=int(input())
	A=list(map(int,input().split()))

	BIT=BitIndexedTree(N)

	for n in range(N):
		BIT.add(n+1, A[n])

	ans = 0
	for n in range(N-1):
		
		
		ans += ((A[n] * BIT.sum(n+2,N)) % MOD)


	print(ans % MOD)

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

Solution (Python):
if __name__ == '__main__':

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

    
    sm = sum(A) ** 2
    
    com = sum([i * i for i in A])

    ans = (sm - com) // 2
    print(ans%(10**9+7))

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

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

sum_A = sum(A)

total = 0

for i in range(n):
    sum_A = sum_A - A[i]
    total += (sum_A * A[i]) % (10**9 + 7)
    total %= (10**9 + 7)
print(total)

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

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

S = sum(A) % MOD
ans = 0


for x in A:
    S -= x  
    S %= MOD  
    ans += S * x
    ans %= MOD

ans %= MOD  
print(ans)

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

mod = 10 ** 9 + 7
ans = 0

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

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

print(ans)

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

mod = 10 ** 9 + 7
ans = 0

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

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

print(ans)

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

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

Solution (Python):
from itertools import accumulate

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

cumsum = [0] + list(accumulate(a))
sum_a = cumsum[-1]
mod = 10**9 + 7
res = 0
for i in range(n):
    res += a[i] * (sum_a - cumsum[i+1])
    res %= mod
print(res)

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

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

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


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

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

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

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

Solution (Python):
N=int(input())
l=[int(i) for i in input().split()][:N]
arr=[-1]*N
arr[0]=l[0]
for i in range(1,N):
    arr[i]=arr[i-1]+l[i]
cnt=0
for i in range(N-1):
    cnt+=(l[i]*(arr[-1]-arr[i]))%1000000007
print(cnt%1000000007)

Solution (Python):
import itertools

n=int(input())
a_list=list(map(int,input().split()))
sum=0
ps = list(itertools.accumulate(a_list))
for i in range(n-1):
  sum+=a_list[i]*(ps[n-1]-ps[i])

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

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

Solution (Python):
n = int(input())
nums = [int(x) for x in input().split()]
multinums = [0]
total = 0

for i in range(0,n):  
    multinums.append(multinums[i]+nums[i])



for i in range(0,n):
    
    total += nums[i] * (multinums[n]-multinums[i+1])

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
P = 0
S = sum(A)
m = 10**9+7

for i in range(N):
  S -= A[i]
  P += A[i]*S
  
ans = P%m
print(ans)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
mod=10**9+7
S=sum(a)%mod
T=sum([i*i for i in a])%mod
print((pow(2,mod-2,mod)*(S*S-T))%mod)

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

s = sum(a)
ans = 0
mod = 10 ** 9 + 7

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

ans = ans % mod
print(ans)

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

ans = 0
s = sum(A)
for i, x in enumerate(A):
	s -= x
	ans += s * x
	ans %= 10 ** 9 + 7

print (ans)

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

Solution (Python):
m = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
x = 0
s = [x := x + c for c in a]
ans = 0

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

Solution (Python):

from itertools import accumulate
def resolve():
    MOD = 10**9+7
    N = int(input())
    A = list(map(int, input().split()))

    Acc = [0] + list(accumulate(A))

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

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
mod = 1000000007

n = int(input())
a = list(map(int, input().split(' ')))
b = [0] * (n + 1)

for i, v in enumerate(a):
    b[i+1] = (b[i] + v) % mod

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

print(ans)

Solution (Python):
MOD=1000000007
N=input()
A = list(map(int,input().split()))
l=len(A)
s=0
B=sum(A)
for i in range(l):
    B-=A[i]
    s+=A[i]*B
print(s%MOD)

Solution (Python):

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) % mod

print(ans%mod)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    MOD = 10 ** 9 + 7
    
    sum_a = sum(A)
    ans = 0
    for ai in A:
        sum_a -= ai
        ans += ai * sum_a
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):


import sys
input=sys.stdin.readline

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
ans=sum(arr)*sum(arr)
for val in arr:
    ans-=(val*val)%mod
print((ans*pow(2,-1,mod))%mod)

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

n = int(input())
a = readInt()



b = 0
ans = 0
for i in a:
    i %= 10**9+7 


s = sum(a)
s2 = sum(map(lambda x:x**2,a))

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

ans %= (10**9+7)

print(ans)

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

S = [A[0]]

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

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

print(_sum)

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

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

all_a = 0

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

for i in range(n):
    all_a = all_a - a[i]
    number = number + (a[i] * all_a)
    number = number % mod
amari = number % mod
print(amari)

Solution (Python):
from collections import deque

N = int(input())
A = list(map(int,input().split()))
allsum = 0
sums_list = deque()
sums = 0
for i in range(N-1, 0, -1):
  sums = (sums + A[i]) % (10**9 + 7)
  sums_list.appendleft(sums)
for i in range(N-1):
  allsum = (allsum + A[i] * sums_list[i]) % (10**9 + 7)
print(allsum)

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

Solution (Python):
N = int(input())
A_ = list(map(int, input().split()))
A = []
mod = 10 ** 9 + 7
for i, a_ in enumerate(A_[::-1]):
    if i == 0:
        A.append(a_ % mod)
    else:
        a = (a_ + A[-1]) % mod
        A.append(a)
A = A[::-1]
A = A[1:]
ans = 0
for i, a in enumerate(A_[:-1]):
    ans += A[i] * a % mod
    ans %= mod

print(ans)

Solution (Python):
import sys
 
def main():
    def input():return sys.stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split(" ")))
 
    mod = 10**9+7
    res = 0

    S = sum(A)
    S2 = sum(map(lambda x: x**2, A))
    print((S**2-S2) // 2 % mod)
if __name__ == "__main__":
    main()

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

Solution (Python):

int_n = int(input())
list_tmp = list(map(int, input().split()))
 
int_sum = 0
int_divide = (10**9) + 7
int_sum_tmp = sum(list_tmp)

for i in range(0, len(list_tmp) - 1):
  int_sum_tmp = int_sum_tmp - list_tmp[i]
  int_sum = int_sum + (int_sum_tmp * list_tmp[i])
print(int_sum % int_divide)

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

s = sum(A)
S = s**2
D = sum([a**2 for a in A])

print(int((S - D) // 2) % mod)

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

Solution (Python):


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

mod = 1000000007
sm = 0

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(int(res))

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

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

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

print(count)

Solution (Python):
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

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

print(sum)

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

n = int(input())
a = readInt()



b = 0
ans = 0
for i in a:
    i %= 10**9+7 


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

ans %= (10**9+7)

print(ans)

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

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

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

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

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

ans *= pow(2, MOD-2, MOD)
ans %= MOD
print(ans)

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

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

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

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_sum = sum(a)
aa = np.array(np.cumsum(a),dtype="object")
all_a = sum(a)

mod = 1000000007

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

print(ans%mod)

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

sq_sum_a = sum(a)**2
sum_sq_a = sum(map(lambda x: x**2, a))

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod

print(ans)

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_sum = sum(a)
aa = np.array(np.cumsum(a),dtype="object")
all_a = sum(a)

mod = 1000000007

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

print(ans%mod)

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

sum = sum(A)
result = 0

for i in range(N): 
  sum -= A[i]
  result += sum*A[i]

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

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

Solution (Python):
MOD=1000000007
N=input()
A = list(map(int,input().split()))
l=len(A)
s=0
B=sum(A)
for i in range(l):
    B-=A[i]
    s+=A[i]*B
print(s%MOD)

Solution (Python):
import numpy as np
n = input()
a = np.array(list(map(int, input().split())), dtype=object)
print((sum(a)**2 - sum(a**2)) // 2 % (10 ** 9 + 7))

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

ans = 0

ans = sum(nums) * sum(nums) - sum([num*num for num in nums])

print((ans // 2) % mod)

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

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

total=sum(alst)
sum=0







for a in alst:
  sum = sum+a * (total - a)
  sum %= MOD

sum *= pow(2, MOD - 2, MOD)
sum %= MOD
print(sum)

Solution (Python):
mod = 1000000007
N = int(input())
A = list(map(lambda x: int(x) % mod, input().split(" ")))

"""
累積話を計算しておく: O(N)
"""
_sum = 0
for i in range(N):
    _sum += A[i]
    _sum %= mod

"""
1重ループ内で下記を行う: O(N)

- 端のブロックを累積和から崩す（減算）
- 端のブロックと累積和をかける
- modをとる
"""
ans = 0
for i in range(N):
    
    _sum -= A[i]

    ans += A[i] * _sum
    ans %= mod

print(ans)

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

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

    print(ans)


if __name__ == "__main__":
    main()

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


if __name__ == '__main__':
    main()

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

    M = 10 ** 9 + 7

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


main()

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0]*(n+1)
    MOD = 10**9 + 7

    for i in range(n):
        b_list[i+1] = b_list[i] + a_list[i]
    
    ans = 0
    for i in range(n):
        ai_sum = b_list[n] - b_list[i+1]
        ans += ai_sum * a_list[i]
        ans %= MOD
    print(ans)




    


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
s2 = sum(map(lambda x:x*x, a))
print((s**2-s2)//2 % (10**9+7))

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

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

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

all_a = 0

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

for i in range(n):
    all_a = all_a - a[i]
    number = number + (a[i] * all_a)
    number = number % mod
amari = number % mod
print(amari)

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

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

Solution (Python):





import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *


BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def main():
    n=int(input())
    a=list(map(int,input().split()))
    prefix=[a[0]]
    mod=10**9+7
    for i in range(1,len(a)):
        temp=prefix[-1]%mod+a[i]%mod
        prefix.append(temp%mod)
    s=0
    for i in range(len(a)-1):
        s=s+a[i]*(prefix[-1]-prefix[i])
        s=s%mod
    print (s)
if __name__ == "__main__":
    main()

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

for i in range(1,n):
    cum[i]=cum[i-1]+arr[i]
    cum[i]%=mod

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
val = sum(a[1:])

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

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

for i in range(n):
    a_sum += a[i]
    s.append(a_sum)

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

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

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

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

Solution (Python):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype = 'object')
mod = 10**9 + 7

sq_sum_a = sum(a)**2
sum_sq_a = sum(a**2)

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod


print(ans)

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

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

print(ans % MOD)

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

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

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

ans = ans % MOD

print(ans)

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

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

ans = ans % MOD

print(ans)

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

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

mod=1000000007
S=0
sl=0

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

print(S)

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

Solution (Python):
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

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

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

Solution (Python):
N = int(input())
a = [int(s) for s in input().split()]
ans = int(0)
temp = int(0)
MOD = int(1000000007)
sumari = sum(a)

for i in range(N-1):
  sumari = sumari - a[i] 
  temp = sumari % MOD
  temp = temp * a[i]
  temp = temp % MOD
  ans += temp
  ans = ans % MOD
print(ans)

Solution (Python):

n = int(input())
item = [int(i) for i in input().split()]
mod = 10**9+7
t = (sum(item)**2 - sum([i**2 for i in item]))

print(int(t * pow(2, -1, mod)) % mod)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
Sum = sum(A)
square_sum = sum(map(lambda x:x*x, A))
print((Sum*Sum - square_sum)//2%(10**9+7))

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

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

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

Solution (Python):
mod = 10 ** 9 + 7
n = int(input())
a_list = list(map(int, input().split()))
result = 0
a_sum = sum(a_list)
for i in a_list:
    a_sum -= i
    result += i * a_sum
print(result % mod)

Solution (Python):
N = int(input())
A = [int(T) for T in input().split()]
SumA = [0]*(N+1)
for TN in range(0,N):
    SumA[TN+1] = SumA[TN]+A[TN]
Sum = 0
Mod = 10**9+7
for TA in range(1,N):
    Sum += (A[TA]*SumA[TA])%Mod
print(Sum%Mod)

Solution (Python):
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
wa = []
total = 0
for i in reversed(range(1, len(an))):
    total = total + an[i]
    wa.append(total)
wa = sorted(wa, reverse=True)
ans = 0
for i in range(0, n-1):

    ans = ans + an[i] * (wa[i]%m)
    ans = ans % m
print(ans)