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):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7

res = 0
s = 0
for i in range(1, len(a)):
    s = (s+a[i-1])%mod
    res = (res+(s*a[i])%mod)%mod

print(res)

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()))
total = sum(a)
mod = 10**9 + 7
ans = 0

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

print(ans)

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

area = sum(l) * sum(l)

for i in l:
    area -= i*i

ans = area//2
ans = ans % mod
print(ans)

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

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

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0





sum = A.sum() % (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)


ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

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

MOD = 10**9 + 7

S1, S2 = 0, 0
for a in A:
    S1 += a
    S2 += a * a % MOD
    S1 %= MOD
    S2 %= MOD

print(((S1*S1%MOD-S2+MOD) % MOD) * pow(2,MOD-2,MOD) % MOD)

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0


for x in A:
  sum += x
  sum %= (10**9+7)


sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)


ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

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

S = sum(li)
li2 = [x**2 for x in li]
S2 = sum(li2)

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

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

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

sq_sum = sum(map(lambda x: x*x, A))
sum_sq = sum(A) * sum(A)
answer = (sum_sq - sq_sum) // 2

print(answer % mod)

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)
sum = A.sum() % (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Solution (Python):
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

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

area=sum(s)*sum(s)   
for i in s:
	area-=i*i
    
ans=area//2
ans=ans%(10**9+7)
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    c = [0]*(N)
    c[0] = A[0]%(1000000007)
    for i in range(1,N,1):
        c[i] = c[i-1]+( A[i]%(1000000007) )
        c[i] = c[i]%(1000000007)
    ans = 0
    for i in range(0,N-1,1):
        A[i] = A[i]%(1000000007)
        tmp = (A[i]*(c[N-1]-c[i]))%(1000000007)
        ans += tmp

    return ans%(1000000007)

print(main())

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

Solution (Python):

n = int(input())
mod = 1000000007
a = list(map(int,input().split()))
width = 0
ans = 0
for i in range(n):
    ans = (ans + a[i]*width)  % mod
    width = (width + a[i]) % mod

print(ans)

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

s.pop(0)

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

Solution (Python):


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

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


if __name__ == "__main__":
    main()

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

A = list(map(lambda x: int(x), input().split(' ')))

res = ((sum(A)**2 - sum(list(map(lambda x: x**2, A)))) // 2) % (10**9 + 7)

print(int(res))

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

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

Sum = sum(A)

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

ans %= 1000000007

print(int(ans))

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

A2=[int(x)**2 for x in A]
print(((sum(A)**2-sum(A2))//2)%(10**9+7))

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

mod = 10**9+7

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

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

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

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

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

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

Solution (Python):

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

    
    square = sum(A) ** 2

    
    diag = sum([a * a for a in A])

    ans = (square - diag) // 2
    print(ans % MOD)


if __name__ == "__main__":
    resolve()

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

s = sum(a)
t = sum(map(lambda x:x**2,a))
ans = ((s**2 - t)//2) % (10**9 + 7)
print(ans)

Solution (Python):


n = int(input())
a = list(map(int, input().split()))
mod = int(1e9)+7

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

Solution (Python):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
S = sum(A) % mod
for i in range(n):
  S =(S- A[i]) % mod
  ans += S * A[i]
  ans %= mod
print(ans)

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

Solution (Python):
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    mod = 10**9+7
    
    a_cum = [0] * (n+1)
    for i in range(n):
        a_cum[i + 1] = a_cum[i] + A[i]
    ans = 0
    for i in range(len(A)-1):
        ans += A[i] * (a_cum[n] - a_cum[i+1])
    ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

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

    mod = 10 ** 9 + 7
    ans = 0
    x = 0

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

    print(ans)

if __name__ == '__main__':
    abc177_c_2()

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

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):
n=int(input())
mod=10**9+7
a=[int(x) for x in input().split()]
a.sort(reverse=True)
ruiseki=[a[0]]
for i in range(1,n):
  ruiseki.append(a[i]+ruiseki[i-1])

ans=0
ruiseki.sort(reverse=True)

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

print(ans%mod)

Solution (Python):
'''
（公式解説参照）
A[i]*A[i+1]+A[i]*A[i+2]+…+A[i]*A[N]=A[i]*(A[i+1]+A[i+2]+…+A[N])
リストAに対する累積和を求めておく
'''
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7


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



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

print(ans)

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

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

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

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)
mod = 10**9+7
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
  
print(modinv(2)*int(findProductSum(a, n))%mod)

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

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

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

c = S
d = 0
for j in range(N):
  c -= A[j]
  c = c%(10**9+7)
  d += A[j]*c
  d = d%(10**9+7)
  
print(d)

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

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


def main():
    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = (sum(A)**2) % MOD - (sum(pow(a, 2, MOD) for a in A)) % MOD
    ans *= pow(2, MOD-2, MOD)
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
p = 10**9+7
n = int(input().rstrip())
a_ls = list(map(int, input().rstrip().split(" ")))
a_ls = [a%p for a in a_ls]
a2_ls = [(a**2)%p for a in a_ls]
a_sum_sq = ((sum(a_ls))**2)%p
a2_sum = sum(a2_ls)%p
ans = (a_sum_sq-a2_sum)%p
if ans%2 != 0:
  ans += p
ans //= 2
print(ans)

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

tot = 0
sqr = 0
ind = 0
for i in range(n):
  tot += a[i]

sqr = tot*tot
for i in range(n):
  ind += a[i]*a[i]

print(((sqr-ind)//2)%1000000007)

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

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

sum_num = 0
sum_list = []
for num in num_list:
  sum_num += num
  sum_num = sum_num % mod
  sum_list.append(sum_num)

answer = 0
for i in range(N):
  sum_num -= num_list[i]
  sum_num = sum_num if sum_num >= 0 else sum_num + mod
  answer += num_list [i] * sum_num
  answer = answer % mod

print(answer)

Solution (Python):

N = int(input())
num_list = list(map(int, input().split(' ')))

list_sum = sum(num_list)

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

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

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

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

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

Solution (Python):
def square(list):
    return [i ** 2 for i in list]
m = 1000000007
n = int(input())
A = list(map(int, input().split()))
sq = square(A)
s1 = sum(A)
s2 = sum(sq)
 
result = (s1**2-s2)//2
print(result%m)

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

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

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

print(ans)

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())
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):
mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in a:
    ans += i
ans = ans**2
for i in a:
    ans -= i**2
print((ans//2)%mod)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    nums = tuple(map(int, input().split()))
    mod = 10 ** 9 + 7

    num_sum = sum(nums)
    part_sum = sum(map(lambda x: x**2, nums)) 

    print((num_sum**2 - part_sum) // 2 % mod)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
S2 = sum(map(lambda x:x**2,A))
 
print((S**2-S2)//2%(1000000000+7))

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

total = sum(data)

ans = 0
for a in data:
    total -= a
    ans += a*(total)
    ans %= mod

print(ans)

Solution (Python):
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
mod = 10**9 + 7
cum = [0] + list(itertools.accumulate(A))
ans = 0
for a, c in zip(A, cum):
    ans += a * c
    ans %= mod
print(ans)

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

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

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

ans = ans % m

print(ans)

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

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

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

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

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

print(sum % 1000000007)

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

cum_sum = 0
cum_sum_list = []
for i in range(N + 1):
    cum_sum += A_list[i]
    cum_sum_list.append(cum_sum)

ans = 0
for i in range(1, N+1):
    ans += A_list[i] * (cum_sum_list[N] - cum_sum_list[i])
    ans = ans % 1000000007
print(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
    
print(ans%((10**9)+7))

Solution (Python):


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

modulus = 10 ** 9 + 7

s = sum(a)
sq = sum(x * x for x in a)
print(((s * s - sq) // 2) % modulus)

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

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

total_rev = [0] * (N + 1)
for i in range(N):
    total_rev[i] = total[N] - total[i]

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

print(ans)

Solution (Python):
import sys
import numpy as np
import math
import collections
import copy
import decimal
import itertools
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations
 

N = int(input())
An = list(map(int, input().split()))
An_l = list(itertools.accumulate(An))
An_l.insert(0, 0)
ans = 0
for i, A in enumerate(An):
    tt = An_l[-1] - An_l[i+1]

    At = A * tt

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

print(ans)

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

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

c_sum = sum(A)
mod = 10**9 + 7
ans = 0

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
total = sum(A)
ans = (sum(list(map(lambda a: (total-a)*a, A))) // 2) % mod
print(ans)

Solution (Python):
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
total2 = 0

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

for i in range(n):
    total2 += int(a[i])*(tmp-int(a[i]))
    tmp -= int(a[i])

print(total2%1000000007)

Solution (Python):
def main():
    input()
    array = (int(x) for x in input().split())
    mod = 10 ** 9 + 7
    ans = 0
    multiplier = 0
    for x in array:
        ans = (ans + x * multiplier) % mod
        multiplier = (multiplier + x) % mod
    return ans


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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    MOD = 10 ** 9 + 7

    ruiseki = [0] * N

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

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

    print(ans)

    

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def main():
    input()  
    array = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7
    total = 0
    center_blocks = 0
    for x in array:
        total += x
        center_blocks += x ** 2
    total = total ** 2
    return (total - center_blocks) // 2 % mod


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

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

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


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

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

sq_sum = sum(map(lambda x: x*x, A))
sum_sq = sum(A) * sum(A)
answer = (sum_sq - sq_sum) // 2

print(answer % mod)

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
al = inpl()
rui = []
for i in range(n):
    if(i == 0):
        rui.append(al[i])
    else:
        rui.append(rui[i - 1] + al[i])

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

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

mod = 10**9 + 7

print(((sum(A)**2 - sum([i**2 for i in A]))//2) % mod)

Solution (Python):
from itertools import accumulate

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

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

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

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

ans=sum(a)%mod
ans**=2

for ai in a:
    ans-=ai*ai
    ans%=mod

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

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

S = sum(A)
S2 = sum(map(lambda x: x**2, A))
print(((S**2 - S2)// 2)%M)

Solution (Python):
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(input())
def m_in(type_): return map(type_, input().split())
def r_in(n, type_): return [type_(input()) for _ in range(n)]
const = 1000000007
ans = 0

n = i_in()
a = l_in(int)

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

print(ans%const)

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

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

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

s = sum(A)
sumpro = 0

for a in A[:-1]:
	s -= a
	sumpro += a * s

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

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

ans = 0
for a in A:
    S -= a
    ans += S * a
    ans %= MOD
print(ans)

Solution (Python):

import sys
import itertools

def main():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    b = list(itertools.accumulate(a))

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


if __name__ == '__main__':
    main()

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
    ans %= mod
print(ans)

Solution (Python):

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x-1)
def lower_bound(li, num): 
	answer = -1
	start = 0
	end = len(li)-1

	while(start <= end):
		middle = (end+start)//2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer 
def upper_bound(li, num): 
	answer = -1
	start = 0
	end = len(li)-1

	while(start <= end):
		middle = (end+start)//2

		if li[middle] <= num:
			answer = middle
			start = middle + 1
		
		else:
			end = middle - 1
	return answer 

def abs(x):
	return x if x >=0 else -x
def binary_search(li, val, lb, ub): 
	ans = 0
	while(lb <= ub):
		mid = (lb+ub)//2
		
		if li[mid] > val:
			ub = mid-1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
def kadane(x): 
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far,current_sum)
	return sum_so_far
def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum


'''
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
   ▄███████▀▀▀▀▀▀███████▄
░▐████▀▒▒Aestroix▒▒▀██████
░███▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀████
░▐██▒▒▒▒▒KARMANYA▒▒▒▒▒▒████▌         ________________
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌  ? ?   |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒|
░░█▒▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▒▐███▌   ?    |___CM ONE DAY___|
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▒▐███▌     ? ? |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒|
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌    ? ?    
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌      ? 
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█     ? ? 
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀       ? 
░░░░▄█████████ ████=========█▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
░░░░░████████████████
'''
from math import *

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

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

Solution (Python):

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    ans = 0
    MOD = 10**9 + 7
    totalSum = sum(arr) % MOD
    currSum = 0

    for num in arr:
        currSum += num
        ans = (ans + num * (totalSum - currSum)) % MOD

    return ans % MOD


N = readInt()
arr = readList()

print(solve(N, arr))

Solution (Python):

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    ans = 0
    MOD = 10**9 + 7
    prefixSums = [0]

    for num in arr:
        prefixSums.append(prefixSums[-1] + num)

    for i, num in enumerate(arr):
        ans = (ans + num * (prefixSums[-1] - prefixSums[i+1])) % MOD

    return ans % MOD


N = readInt()
arr = readList()

print(solve(N, arr))

Solution (Python):
import math

N = int(input())
lst = list(map(int, input().split(' ')))
cur_sum = sum(lst)

ans = 0
for val in lst:
    cur_sum -= val
    ans += cur_sum * val
    ans %= (math.floor(math.pow(10,9)) + 7)

ans %= (math.floor(math.pow(10,9)) + 7)
print(ans)

Solution (Python):
n = int(input())
lis = list(map(int, input().split()))
mod = 1000000007
pre = [0] * n
su = 0
total = sum(lis)
for i in range(n):
    su += lis[i]
    pre[i] = su
suf = [0] * n
for i in range(n):
    suf[i] = total-pre[i]
ans = 0
for i in range(n):
    ans = (ans + (lis[i] * suf[i]) % mod) % mod
print(ans)

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

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

Solution (Python):

import sys
from itertools import accumulate
MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    aa = list(accumulate(A))
    
    x = sum(A)
    

    ans = 0

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

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

    total = sum(A) % MOD

    ans = total * total % MOD
    for a in A:
        ans = (ans - a * a) % MOD

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate

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

sa = list(accumulate(a))
mod = 10 ** 9 + 7
ans = 0
for i in range(n - 1):
    ans += a[i] * (sa[-1] - sa[i])
    ans %= 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())

    total = sum(A)

    ans = 0
    for a in A:
        total -= a
        ans = (ans + a * total % MOD) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

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

for i in range(n):
    c-=aa[i]
    total+=aa[i]*c
   
x=10**9+7
ans=total%x
print(ans)

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):
import sys
from itertools import accumulate
n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
aa = list(accumulate(a))
MOD = 10**9+7
ans = 0
for i in range(n):
    ans += a[i]*(aa[n-1] - aa[i]) % MOD
    ans %= MOD
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,(input().split())))
total = 0
result = 0
MOD = pow(10,9)+7
l = []

for i in range(N):
    total += A[i]
    l.append(total)

for i,num in enumerate(l):
    temp = total-num 
    result += temp*A[i]

print(result%MOD)

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) % mod
ans = 0
for a in A[:-1]:
  sum_A -= a
  sum_A %= mod
  ans += a * sum_A
  ans %= mod

ans %= mod
print(ans)