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



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

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

m = sum(A)
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(A)
ans = 0
for i in range(n-1):
    s -= A[i]
    ans = (ans + A[i] * s) % int(1e9 + 7)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2
summation2 = sum(b ** 2 for b in B)
summation = ((summation1 - summation2) // 2) % x
print(summation)

Submission status: Accepted

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

sum_A = sum(A)

mod = 10**9 + 7

sum_mod = 0

sum_minus = 0
for a in A:
    sum_mod += a * (sum_A - a - sum_minus) % mod
    sum_minus += a

print(sum_mod % mod)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    R = [0]
    MOD = 10**9 + 7
    ans = 0
    for i in range(N):
        R.append(A[i]+R[-1])
    for i in range(N-1):
        ans += A[i] * (R[-1] - R[i+1])
        ans %= MOD
    print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7
sum_A = 0
for i in range(N):
    sum_A = (sum_A + A[i]) % MOD

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


print(sum)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
Asum = sum(A) % (10**9 + 7)
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
b = [0] * n
c = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
#if l[i] == l[j]: continue
n = int(input())
a = list(map(int, input().split()))
ans = 0
min = 0
new_list = list(reversed(a))

for i in range(len(new_list) - 1):
    min += new_list[i]
    ans +=  min * new_list[i+1]


print(ans % 1000000007)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))

ans = 0

S = sum(L)
for i in range(len(L)-1):
    ans += L[i] * (S- L[i])
    S -= L[i]
    
print(ans % (10**9 + 7))

Submission status: Accepted

Solution code:
m = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7
ans = 0

tmp_sum = sum(a[1:m]) % mod

for x in range(m-1):
  if a[x] % mod != 0:
    ans += (a[x] * tmp_sum) % mod
  
  tmp_sum -= a[x+1] % mod

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod=10**9+7
def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod
def mul(x,y):
  return (x%mod)*(y%mod)%mod
def add(x,y):
  return (x+y)%mod

n=int(input())
alist=list(map(int,input().split()))
s=sum(alist)%mod
print(mul(add(mul(s,s),-sum(mul(a,a) for a in alist)),power(2,mod-2)))

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int, input().split()))
ans=sum(l)**2

sq=0
for i in range(n):
  sq+=l[i]**2
ans=(ans-sq)//2

import numpy as np
print(np.mod(ans, 10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

#print(a)
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
    # for j in range(i+1,N):
    #     #print(a[i],a[j])
    #     s = (s + (a[i]*a[j])%di)%di
print(s)

# import sys,collections
# sys.setrecursionlimit(1000000)
# INF = float("inf")

# Q = int(sys.stdin.readline())
# ab = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)) # multi line with multi param
# N = 1000001

# cum=[0]*(N+1)

# for l,r in ab:
#     cum[l] += 1
#     if r+1 < N+1: cum[r+1] -= 1

# ret = cum[0]
# for i in range(N):
#     cum[i+1] += cum[i]
#     ret = max(ret,cum[i+1])

# print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(A_sum_list)
print(ans%(10**9 + 7))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

Submission status: Accepted

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

Submission status: Accepted

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

## 高々 N(N-1)/2　< 2 * 10^10 のため何とかなる...?
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)
'''

### a1　は a2~an(= S)までの和を必要とする. a2 は S - a2 (=S). a3 は S - a3...

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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
    #print(f"{a}*{cum_A[N] - cum_A[i + 1]}")
    ans += a * ((cum_A[N] - cum_A[i + 1]) % mod)
    ans %= mod
    #print(ans)
print(ans)

Submission status: Accepted

Solution code:
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
# print(l)
for i in range(1, n):
    s+=((a[i]%mod)*(l[i-1]%mod))%mod
    s%=mod
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math  # gcdもあるよ
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):
        #print(N[i] , sum(N[i + 1:]))
        ans += (N[i] * sum(N[i + 1:])) % INF
        ans %= INF
    """
    # ans = sum(N)  /2
    N2 = [pow(i, 2, INF) for i in N]
    N3 = pow(sum(N), 2, INF)
    #print(N2, N3)
    N4 = (N3 - sum(N2))
    if N4 % 2 == 1:
        N4 += INF
    ans = (N4 / 2) % INF
    print(int(ans))
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import decimal
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
_ = 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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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_)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
    #print(sum_a-a)
ans //= 2

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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