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:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	n = int(rl())
	A = list(rli())
	psums = [A[0]]
	ans = 0
	for i in range(1, n):
		psums.append(psums[-1] + A[i])
	for j in range(1, n):
		ans += psums[j-1] * A[j]
		ans %= MOD 
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=1000000007
sum=0
tmp=0
o=0
while(o<n):
    tmp = (a[o]%mod + tmp%mod)%mod
    o += 1

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



print(sum%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
sum_a = [0]*n
sum_a[0] = a[0]
for i in range(1, n):
    sum_a[i] = sum_a[i-1] + a[i]
#print(sum_a)
ans = 0
for i in range(n):
    sum_i = sum_a[n-1] - sum_a[i]
    ans = (ans + sum_i*a[i] % mod) % mod
print(ans % mod)

Submission status: Accepted

Solution code:
mod = 10**9+7
n = int(input())
input_list = list(map(int,input().split()))
input_len = len(input_list)
remain_num = sum(input_list[1:])
remain_list = [remain_num]
for i in range(1,input_len):
    remain_list.append(remain_list[i-1]-input_list[i])

temp = 0
for i in range(input_len):
    temp = (temp+input_list[i]*remain_list[i])%mod
print(temp)

Submission status: Accepted

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

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

wa = wa%mod
wa -= A[0]    

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

print(ans%mod)

Submission status: Accepted

Solution code:
mod = 10**9 + 7


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

cumsum = A[:]
for i in range(N - 1)[::-1]:
    cumsum[i] += cumsum[i + 1]
    cumsum[i] %= mod

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

print(ans)

Submission status: Accepted

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

sum_a = 0
mul_a = 0
mod = 1000000007

for a in a_s:
    sum_a += a
    mul_a += a*a
    sum_a %= mod
    mul_a %= mod

ans = sum_a * sum_a
ans %= mod
ans -= mul_a
ans %= mod

n = mod-2
inv = 1
base = 2

while n:
    if n & 1:
        inv = inv*base % mod
    base = base*base % mod
    n >>= 1

ans *= inv
ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def NLI(n):return [[int(i) for i in input().split()] for i in range(n)]
def NLI_(n):return [[int(i)-1 for i in input().split()] for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
#mo=998244353
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

ans=0


s=5*10**8+4

n=I()
a=LI()
A=sum(a)%mo
ans=(A*A-sum([i**2 for i in a]))*s
print(ans%mo)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a) * sum(a)
for i in range(n):
    sum_a -= a[i] * a[i]
sum_a = sum_a // 2
print(sum_a % (1000000000 + 7))

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
INf=float('inf')

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

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

print(ans%mod)

Submission status: Accepted

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

sumA, mod, ans = [0], 10 ** 9 + 7, 0
for a in A:
    sumA.append((sumA[-1] + a) % mod)

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
ruisekiwa = [0] * n
cnt = 0
ruisekiwa[0] = a[0]
for i in range(1,n):
    ruisekiwa[i] = ruisekiwa[i-1] + a[i]
for i in range(n):
    cnt += a[i] * (ruisekiwa[-1] - ruisekiwa[i])
print(cnt % (10**9 + 7))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in a :
    s -= i
    s %= MOD
    ans += i * s
    ans %= MOD
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9) + 7
R = [0 for _ in range(N+1)]
for i in range(N):
  R[i+1] = R[i] + A[i]
S = 0
for i in range(N-1):
  S += A[i] * (R[N] - R[i+1]) % mod
  S %= mod
print(S)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 177
# C - Sum of product of pairs

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

mod=10**9+7

ans=0
accumls=[0]

for i in range (N):
    accumls.append(accumls[-1]+ls[i])

for i in range (N-1):
    ans+= ls[i]*(accumls[-1]-accumls[i+1])
    ans%=mod

print(ans)

Submission status: Accepted

Solution code:
k = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
S = sum(L) ** 2
for i in L:
  S -= i ** 2

print( (S // 2) % k)

Submission status: Accepted

Solution code:
n = int(input())

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

S = sum(a)

S2 = sum(map(lambda x: x * x, a ))

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

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
MOD = 10**9 + 7
tmp = sum(a) % MOD
ans = 0
for i in range(n-1):
    tmp -= a[i]
    ans += tmp * a[i] % MOD
    ans = ans % MOD
print(ans)

Submission status: Accepted

Solution code:
INF = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
S = [sum(A)]#A[0]~A[N-1]の総和を求める

ans = 0
for i in range(N-1):
    key = S[-1]#Sの一番後ろの配列をとる(要素は一つしかない)
    S.append(key - A[i])#総和からA[i]を引いてあげたものをS配列に加えてあげるS配列はみぎに行くにつれて値が小さくなる
    #print(S)
    ans += (A[i] * S[-1])#Ansは実際の総和計算に当たるもの

print(ans%INF)

Submission status: Accepted

Solution code:
P = 10**9 + 7

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

S, T = 0, 0
for i in range(N):
    S = (S + A[i]) % P
    T = (T + A[i] * A[i]) % P

U = (S * S - T) % P
ans = (U * (5 * 10**8 + 4)) % P
print(ans)

Submission status: Accepted

Solution code:
################ C
n = int(input())
nums = list(map(int, input().split()))

total = 0
total_sum = sum(nums)
for num in nums:
    total_sum -= num 
    total += num * total_sum
    
print(total % 1000000007)

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):
  a = A[i]
  S -= a
  ans += a * S

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

Submission status: Accepted

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


def main():
    from itertools import accumulate

    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    summed_a = list(accumulate([0] + a))
    mod = 10 ** 9 + 7
    ans = 0

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

    print(ans % mod)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
MOD = int(1e9+7)

if __name__ == "__main__":
    n = int(input())
    a = [int(i) for i in input().split()]

    sum_a = sum(a) % MOD

    result = 0 

    for value in a:
        sum_a -= value
        result = int(result + value * sum_a) % MOD
    
    print(result)

Submission status: Accepted

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

limit=10**9+7
S=[0]
for i in range(N):
    A[i]=A[i]%limit
for i in range(1,N):
    S.append((S[i-1]+A[-i])%limit)
ans=0
for i in range(N-1):
    ans+=A[i]*S[-1-i]
    ans=ans%limit
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

mod = 10 ** 9 + 7
sum_a = sum(a_list)
total = 0
for i, a in enumerate(a_list):
    total += (a * (sum_a - a)) % mod
    sum_a -= a
total = total % mod
ans = total
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = sum(map(lambda x: x ** 2, A))

print(((sum(A) ** 2 - B) // 2) % (10 ** 9 + 7))

Submission status: Accepted

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

Submission status: Accepted

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

B = list(map(lambda x: x ** 2, A))

SA = sum(A)
SB = sum(B)

print(((SA * SA - SB) // 2) % mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10**9+7
S = sum(A)
ans = 0

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

Submission status: Accepted

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

tmp = 0
tmp2 = 0

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

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

print((tmp*tmp-tmp2)//2%1000000007)

Submission status: Accepted

Solution code:
mod = 1000000007
N = int(input())
ruiseki = []
A = list(map(int, input().split()))
sum = 0

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

ruiseki.append(sum - A[0])
if(ruiseki[0] < 0): ruiseki[0] += mod

for i in range(1,N-2):
  ruiseki.append(ruiseki[i-1] - A[i])
  if(ruiseki[i] < 0): ruiseki[i] += mod

ans = 0

for i in range(0,N-2):
  ans += A[i]*(ruiseki[i])%mod

ans += (A[N-2]%mod)*(A[N-1]%mod)%mod
ans = ans%mod
print(ans)

Submission status: Accepted

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

mod = 1000000007
s = sum(a) % mod
ans = 0

for i in a:
    s -= i
    ans += s * i
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
S = [0]*n
for i in range(0, n):
    if i > 0:
        S[i] = S[i-1] + a[i]
    else:
        S[i] = a[i]
ans = int(0)
m = int(1000000007)
for i in range(0, n):
    ans = (ans + (a[i] * (S[n-1]-S[i]))) % m
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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

acc = list(itertools.accumulate(A))
ans = 0
mod = 10**9 + 7

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

print(ans%mod)

Submission status: Accepted

Solution code:
import copy
mod=10**9+7
def calc(nums,n):
    if n==2:
        return ((nums[0]%mod)*(nums[1]%mod))%mod
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save%mod+nums[i+1]%mod)%mod
        save=s%mod
       
    ans=0  
    
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
    





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
Asum=sum(A)
ans=0
for i in range(len(A)-1):
    Asum-=A[i]
    ans+=A[i]*Asum
print(ans%1000000007)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)
    ans = s * s
    for a in A: ans -= a * a
    print((ans // 2) % mod)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Ans = 0
    C = 0
    for i in range(1, len(A)):
        C += A[i-1]
        Ans += A[i]*C % (10**9+7)
    print(Ans % (10**9 + 7))
    
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
ans=0
mod=10**9+7
list1=list(map(int ,input().split()))
sums=sum(list1)

for i in list1:
  sums -=i
  ans +=sums*i%mod
  
print(ans%mod)

Submission status: Accepted

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

mod = 10 ** 9 + 7
total = 0
y = sum(list1)

for i in range(0,n-1):
    y = y- list1[i]
    total += list1[i] * y % mod

total = total % mod
print(total)

Submission status: Accepted

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

ans = sum(a)**2

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 0
den = int(1e9 + 7)
sum_a = [0 for i in range(len(a))]
sum_a[-1] = a[-1]
for i in range(len(a) - 1, 1, -1):
    sum_a[i - 1] = sum_a[i] + a[i - 1]
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum_a[i + 1]) % den

print(ans)

Submission status: Accepted

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

mod = 1000000007

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

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

print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ls = list(map(int, input().split()))
mod = 10**9+7
total = sum(ls)
sq_power = sum(map(lambda x:x*x%mod, ls))
ans = (total**2 - sq_power)%mod
ans2 = 2
for _ in range(9):
    ans2 = (ans2**10)%mod
ans2 *= 2**5 % mod
print(ans*ans2%mod)

Submission status: Accepted

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

tmp = A[-1]
cum = [tmp]
for i in range(1, N-1)[::-1]:
    tmp += A[i]
    cum.append(tmp)
    
cum = cum[::-1]
ans = 0
for i in range(N-1):
    ans += cum[i]*A[i]
    ans %= mod

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


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

    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum_A = sum(A)
ans = 0

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

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N-1,-1,-1):
    su+= (A[i] * a) % mod
    a += A[i]
print(su % mod)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A_str = input()
A_str_list = A_str.split()
A = np.array([int(A_str_list[i]) for i in range(N)])
sum = 0
mod = 1000000007
res = np.cumsum(A)
res = [np.mod((res[-1]-res[i]), mod) for i in range(N)]
# print(res)
for i in range(N):
    sum += np.mod(res[i]*A[i], mod)
print(np.mod(sum, mod))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(N-1,-1,-1):
    su+= A[i] * a
    a += A[i]
print(su % mod)

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

Submission status: Accepted

Solution code:
import math

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

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

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

ans = ans % MOD
print(ans)

Submission status: Accepted

Solution code:
def c_sum_of_product_of_pairs(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    cumsum = [0]
    for a in A:
        cumsum.append(cumsum[-1] + a)
    return sum([(cumsum[N] - cumsum[i + 1]) * A[i] for i in range(N)]) % MOD

print(c_sum_of_product_of_pairs())

Submission status: Accepted

Solution code:
n = int(input())
sz = [int(x) for x in input().split(" ")]

ans = sum(sz)*sum(sz)

for i in sz :
    ans -= i*i

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

print(int(ans))

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
mod = 10**9+7
ruiseki = 0
total=sum(a)
ans = 0
for i in range(N-1):
    ruiseki += a[i]
    ans += a[i] * (total- ruiseki) % mod

print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(' ')
a = 0
sum = 0
for i in range(1, N):
    sum += int(A[i])
for i in range(N):
    a += int(A[i]) *  sum
    if i < N - 1:
        sum -= int(A[i + 1])
    
print(int(a % (10 ** 9 + 7)))

Submission status: Accepted

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

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

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

ans = ans % MOD
print(ans)

Submission status: Accepted

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

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

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

ans = ans % MOD
print(ans)

Submission status: Accepted

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

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

for a in A:
    num -= a
    ans += a * num

print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())

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

B = list(accumulate(A))

d = 10**9+7
s = 0

for i in range(N):
    s += (A[i]*(B[-1]-B[i])) % d
    
print(s % d)

Submission status: Accepted

Solution code:
N = int(input())

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

mod = 10 ** 9 + 7

temp = 0

for i in range(N):

    temp += (A[i] ** 2) 

print(((((sum(A) ** 2) ) - (temp)) // 2) % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_sum_of_product_of_pairs(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

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

    return sum([(total - cumsum[i]) * A[i - 1] for i in range(1, N)]) % MOD

print(c_sum_of_product_of_pairs())

Submission status: Accepted

Solution code:
n = int(input())
la = list(map(int, input().split()))
MOD = 10**9+7
s1 = sum(la)
s2 = sum([x**2 for x in la])
ans = (s1*s1-s2)//2%MOD
print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7

sum_A = [0] * N
sum_A[0] = A[0]

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

print(sum([sa*a for sa,a in zip(sum_A[:-1], A[1:])]) % MOD)

Submission status: Accepted

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

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

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

print(ans % 1000000007)

Submission status: Accepted

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

s_1 = 0
s_2 = 0
m = 10 ** 9 + 7
for i in range(n):
    s_1 += a[i] % m
    s_2 += (a[i] ** 2) % m
s = (s_1 * s_1 - s_2) * pow(2, m - 2) % m
print(s)

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
s = sum(x) - x[0]
ans = 0

for i in range(N-1):
  ans = ans + x[i]*s
  s = s - x[i+1]
ans = ans % 1000000007
  
  
print(ans)

Submission status: Accepted

Solution code:
p = (10 ** 9 + 7) * 2
N = int(input())
A = [int(x) for x in input().split()]
A2 = [(x ** 2) % p for x in A]
result = (((sum(A) % p) ** 2 - sum(A2) % p) % p) / 2
print(int(result))

Submission status: Accepted

Solution code:
# Python template 
from collections import defaultdict 
import sys
import math 

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


n = int(input())
a = get_array()

pre_sum = [0]

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

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

print(ans)

Submission status: Accepted

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

s = sum(A)

for a in A:
    s -= a
    ans += a * s

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
mod = 1000000007

a = [-1] + a
pre = [0]

for i in range(1, n+1):
    pre.append((pre[i-1] + a[i]) % mod)
pre.append(0)

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

print(ans)

Submission status: Accepted

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

ans = 0
sa = sum(a)%mod

for i in a:
    sa -= i
    sa %= mod
    ans += i*sa%mod
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

MOD = 10**9 + 7
ans = 0
s = 0
i = N - 1
for n in range(N - 2, -1, -1):
    s += As[i]
    s %= MOD
    i -= 1
    ans += s * As[n]
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    W = [0]*N
    W[0] = A[0]
    for i in range(1,N):
        W[i] += W[i-1] + A[i]
    ans = 0
    for i in range(N-1):
        ans += A[i]*(W[N-1] - W[i])
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int, input().split()))
mod = int(1e+9+7)
cumsum_list = np.cumsum(num_list[::-1])[::-1][1:]
all_sum = sum(num_list)
score = 0
for i in range(n-1):
    #print(num_list[i], cumsum_list[i])
    score += (num_list[i] * (cumsum_list[i]%mod)) % mod
print(score % mod)

Submission status: Accepted

Solution code:
import numpy as np

mod = 10**9+7
N = int(input())
A = np.array([int(i) for i in input().split()])

sum = A.sum() % mod

#B = np.square(A)
#sum2 = B.sum() % mod

sum2 = 0

for x in A:
  sum2 += x**2
  sum2 %= mod

ans = (sum**2 - sum2) % mod

if ans%2==1 : ans += mod
ans //= 2
ans %= mod
print(int(ans))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int, input().split()))

mod = int(1e+9+7)
cumsum_list = np.cumsum(num_list[::-1])[::-1][1:]
all_sum = sum(num_list)
score = 0
for i in range(n-1):
    #print(num_list[i], cumsum_list[i])
    #score += (num_list[i] * cumsum_list[i]) % mod
    all_sum -= num_list[i]
    score += (num_list[i] * all_sum) % mod
print(score % mod)

Submission status: Accepted

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

for j in range(0,len(A)):
    c+=A[j]

for i in range(0,len(A)):
        c=c-A[i]
        b+=A[i]*c
        
print(b%(10**9+7))

Submission status: Accepted

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

rs=[0]*n
rs[0]=l[-1]
j=1
for i in range(n-2,-1,-1):
    rs[j]=rs[j-1]+l[i]
    j+=1
rs=rs[::-1]

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

Submission status: Accepted

Solution code:
mod = 10**9+7
N = int(input())
a = list(map(int, input().split()))
sum_a = 0
sum_a2 = 0
for x in a:
  sum_a += x
  sum_a2 += x**2

ans = ((sum_a**2 - sum_a2))//2
print(ans%mod)