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:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

n=int(input().rstrip())
a=[int(i) for i in input().split()]

mod=10**9+7

csum=[0]
for i in a:
    csum.append((csum[-1]+i)%mod)

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
mod=pow(10,9)+7
numbers=[]
num=0
for a in A:
    num+=a
    numbers.append(num)
ans=0
last=numbers[-1]
for n in range(N-1):
    number=numbers[n+1]-numbers[n]
    ans+=(number*(last-numbers[n+1]))
ans+=(A[0]*(last-A[0]))
ans=ans%mod
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
L=list(map(int,input().split()))
cnt=0
for i in range(n):
	cnt+=L[i]**2

ans=(sum(L)**2-cnt)//2
mod=pow(10,9)+7

print(ans%mod)

Submission status: Accepted

Solution code:
from itertools import accumulate


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

acc = list(accumulate(A, initial=0))
ans = 0
for i in range(1, N):
    ans += A[i - 1] * (acc[N] - acc[i])
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=read()
a=list(reads())
num=0
l=len(a)
ls=[]
k=0
for i in range(l-1,0,-1):
    k+=a[i]
    ls.append(k)
for i in range(l-1):
    num+=a[i]*ls[-i-1]
num%=10**9+7
print(num)

Submission status: Accepted

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

import functools


M = 10 ** 9 + 7


def sum_mod(xs):
    return functools.reduce(lambda x, y: (x + y) % M, xs) % M


def compute(bs):
    term1 = sum_mod(bs) * sum_mod(bs) % M
    term2 = sum_mod(b * b for b in bs)
    double_res = (term1 - term2) % M
    inv2 = pow(2, M - 2, M)
    res = double_res * inv2 % M
    return res


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    res = compute(bs)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    mod = 10**9 + 7
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = list(it)

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

# In[23]:


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


# In[24]:


mod = 10**9+7
a_sum = sum(A)
a_sum_list = []
cnt = 0
for i,a in enumerate(A):
    a_sum_list += [a_sum-a-cnt]
    cnt += a
mylist = [a_sum_list[i]*a for i,a in enumerate(A)]
ans = sum(mylist)%mod
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
n=int(input())
lis=list(int(x) for x in input().split() )
ans=0
x=10**9+7
su=0
for i in range(len(lis)) :
    su=su+lis[i]
for i in lis :
    su=su-i
    ans=(ans+su*i)%x

print(ans)

Submission status: Accepted

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

su = sum(a)
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    SUM = []
    now = 0
    ans = 0
    for i in range(N):
        now += A[i]
        SUM.append(now)
    
    for i in range(N):
        ans += A[i] * (SUM[-1] - SUM[i])
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    S = sum(A)
    count = S
    ans = 0
    for i in A:
        count -= i
        ans += count*i
        if ans > 10**9+7:
            ans %= (10**9+7)
    print(ans)
resolve()

Submission status: Accepted

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

ans=0
inf=10**9+7
flag=True
total=0
for i in range(N):
    total+=A[i]
    total%=inf

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

Submission status: Accepted

Solution code:
def findProductSum(A, n):

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

    array_sum_square = (array_sum * array_sum)

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

    return ((array_sum_square -
             individual_square_sum) // 2) % (10**9+7)
n=int(input())
a=list(map(int,input().split()))
print(findProductSum(a,n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C
p = 10**9+7

N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
for i in range(1,N):
    B.append(B[-1]+A[i])
#print(B)

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

Submission status: Accepted

Solution code:
N=input()
A=list(map(int, input().split()))
mod=10**9+7
g=sum(A)%mod
r=0
for i in A:
  r+=i**2
  r%=mod
ans=(g**2-r)*pow(2,-1,mod)
ans%=mod
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

data = input().split()

data = [int(s) for s in data]

num = 0
ans = 0
sum = sum(data)

for i in range(N) :
  num += data[i]
  ans += (sum - num) * data[i]

print(ans % 1000000007)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
base = 10 ** 9 + 7
X = 0
Y = 0
for i in A:
  X += i * i
  Y += i
  X %= base
  Y %= base
Y = (Y * Y) % base
ans_ = ( Y - X ) % base

m = pow(2, base-2, base)
#print(m)
print( (ans_ * m) % base )

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)

suma=0
for a in A:
    suma = (suma + a) % P
ans=0
for a in A:
    suma = (suma - a)%P
    ans = (ans + a * suma) % P
print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
n = int(input())
arr = list(map(int, input().split()))
temp = arr[:]
for i in range(n - 2, -1, -1) :
	temp[i] += temp[i + 1]
ans = 0
for i in range(n - 1) :
	ans = (ans + (arr[i] * temp[i + 1]) % mod) % mod
print(ans % mod)

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_sum*(A[i])

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

Submission status: Accepted

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
mod=10**9+7
sum_a=sum(A)
ans=0
for i in range(N):
    sum_a=sum_a-A[i]
    ans+=sum_a*A[i]
    ans%=mod

print(ans)

Submission status: Accepted

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

mod = 10**9 + 7
ans = 0
A_sum = [0]

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
s = [0 for i in range(n)]

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
sum1 = sum(a)
ans=0
for x in a:
	sum1-=x;
	ans+= (x*sum1)
	# print(ans)
print(ans%1000000007)

Submission status: Accepted

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(map(int,input().split())))
    return np.array(x)

def str_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

def int_map():
    return map(int,input().split())

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

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np
import collections as col

# main code
N = int(input())
A = int_list()

sumlist = []
sumlist.append(A[0])

for i in range(1,N):
    sumlist.append((sumlist[i-1]+A[i])%(10**9+7))

a = 0

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

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

Submission status: Accepted

Solution code:
a=int(input())
m_list=list(map(int,input().split()))
sum=sum(m_list)
count=0
for i in range(a) :
  count+=m_list[i]**2

answer=(sum**2-count)//2
print(answer%(10**9+7))

Submission status: Accepted

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

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

ans = 0

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

Submission status: Accepted

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

D=[0]*N
s=0
for i in range(N):
    s += A[i]
    D[i] = s

s = 0
for i in range(1,N):
    a = A[i]*D[i-1]
    s = (s+a)%MOD
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_array = map(int, input().split())
MOD = 10 ** 9 + 7
a_array = [a % MOD for a in a_array]
sum = 0
square_sum = 0
for i in range(n):
    sum += a_array[i]
    sum %= MOD
    square_sum += pow(a_array[i], 2, MOD)
    square_sum %= MOD

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

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
ra=A[::-1]
S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+ra[i]
M=10**9+7

S=S[::-1]
i=0
ans=0
while i<N:
    ans+=A[i]*S[i+1]
    ans%=M
    i+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

sum1 = 0
sum2 = 0

for _ in a:
  sum1 += _
  sum2 += (_*_)
sum1 = (sum1 * sum1)
print(((sum1 - sum2)//2)%1000000007)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n= int(input().strip())
a= list(map(int, input().strip().split()))
x=0
A=0

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

Submission status: Accepted

Solution code:
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

MOD = 10**9 + 7
def main():
	n = int(input()); arr = read()
	pref = [i for i in arr]
	for i in range(1, n):pref[i] += pref[i-1]
	ans = 0
	for i in range(n):
		ans += (arr[i] * (pref[-1]-pref[i]))%MOD
		ans %= MOD
	print(ans)



if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

S=[0]*N
S[0]=A[0]

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

#S=sum(A)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
lsA = list(map(int,input().split()))
sum1 = sum(lsA)
ans = 0
for i in range(N):
    sum1 = sum1 - lsA[i]
    ans += lsA[i] * (sum1 % (10**9+7))
    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=[0]*n
s[0]=a[0]
for i in range(1,n):
    s[i]=(s[i-1]+a[i])%mod

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

print(ss%mod)

Submission status: Accepted

Solution code:
N = int(input())

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

s = sum(A) % mod
s += mod
ss = 0
for i in range(N):
    ss += A[i]**2 % mod

ss = ss % mod
if (s**2 - ss) % 2 == 1:
    ss -= mod

print((((s**2) - ss) // 2) % mod)

Submission status: Accepted

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

abc177c()

Submission status: Accepted

Solution code:
def findProductSum(A, n): 
      
    array_sum = sum(A)
    array_sum_square = array_sum ** 2
    
    individual_square_sum = 0
    for i in range(n): 
        individual_square_sum += A[i] * A[i] 
  
    return (array_sum_square - individual_square_sum) // 2

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

print(findProductSum(A, N)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_list = [int(e) for e in input().split()]

MOD_BY = 10**9 + 7

#全ループするとTLE
#Ai*(自分の右側の合計)で回す

right_sum = sum(A_list)%MOD_BY
ans = 0
for i in range(N-1):
    right_sum -= A_list[i]
    #print(A_list[i],right_sum)
    ans += A_list[i]*right_sum%MOD_BY
    
print(ans%MOD_BY)

Submission status: Accepted

Solution code:
import sys

mod = 10**9+7
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A = LI()
    A_sum = sum(A)
    ans = 0
    for i in range(n-1):
        A_sum -= A[i]
        ans += A[i]*A_sum
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 1000000007

Alist = Alist[::-1]

mod = 0

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

print(ans%MOD)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    all_val = sum(A)
    A = A[::-1]

    sum_val = 0
    for i in range(len(A)):
        all_val -= A[i]
        sum_val += all_val * A[i] % (10**9 + 7)
    return sum_val % (10**9 + 7)

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

Submission status: Accepted

Solution code:
N = int(input())
# N = 2 * 10 ** 5
A = tuple(map(int, input().split()))
# A = [10 ** 9] * N
MOD = 10 ** 9 + 7
rev_sum_list = [0] * N
rev_sum_list[-1] = A[-1]
for i in range(N - 2, -1, -1):
    rev_sum_list[i] = (rev_sum_list[i + 1] + A[i]) % MOD
# print(rev_sum_list)
ans = 0
for i in range(1, N):
    ans += A[i - 1] * rev_sum_list[i]
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
#abc177 c
import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7

N=int(input())
A=list(map(int,input().split()))
Asum = sum(A)
Asum_list = []
for i in range(N):
    Asum -=A[i]
    Asum_list.append(Asum)
ans = 0
for a,b in zip(A,Asum_list):
    ans = (ans + a*b)%m
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        ans += A[i]
        ans %= m
    ans = ans**2
    ans %= m
    for i in range(N):
        ans -= pow(A[i],2,m)
        ans %= m
    
    ans = ans * pow(2,m-2,m) % m
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A_List = [int(i) for i in input().split()]

Y = 0
M = 10**9+7
tempSum = sum(A_List)

for x in A_List:
    tempSum -= x
    Y += x * tempSum
    Y = Y%M
print(Y)

Submission status: Accepted

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

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

mod = int(1e9)+7

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

print(ans%mod)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ss=s**2
c=0
for i in range(n):
    c+=(l[i]*l[i])
p=(ss-c)//2
print(p%1000000007)

Submission status: Accepted

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

p = int(1e9 + 7)

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

Submission status: Accepted

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

mod = 10 ** 9 + 7
sumnumber = sum(AList)

result = 0
for i in AList:
    result += (sumnumber - i) * i
    
    sumnumber -= i

print(result % mod)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
M = 10**9+7

A = np.array(A, np.int64)
a1 = A.sum() % M
a1_sq = a1**2 % M
a2 = (A**2 % M).sum() % M
diff = (a1_sq - a2) % M

if diff % 2 == 0:
    print(diff // 2)
else:
    res = (diff + M) // 2 % M
    print(res)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))
p = 10**9+7
ans = 0

suma = sum(a)
sumaa1 = (suma**2//2)%p

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

ans = (sumaa1-sumaa2)%p

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
div = 10 ** 9 + 7
lst = list(map(int, input().split()))
ACC = list(accumulate(lst))
ACC.pop(n - 1)
res = 0
for i in range(n - 1):
  res += (lst[i + 1] * ACC[i])
  res %= div
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7

def egcd(a, b):
    lastremainder, remainder = abs(a), abs(b)
    x, lastx, y, lasty = 0, 1, 1, 0
    while remainder:
        lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
        x, lastx = lastx - quotient*x, x
        y, lasty = lasty - quotient*y, y
    return lastremainder, lastx * (-1 if a < 0 else 1), lasty * (-1 if b < 0 else 1)


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise ValueError('modinv for {} does not exist'.format(a))
    return x % m

n = int(input())
A = [int(i) for i in input().split()]
ans = sum(A)**2 % mod
for i in A:
    ans -= i**2
    ans %= mod
ans *= modinv(2, mod)
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
su=sum(a)
com=0
mod=pow(10,9)+7
for i in range(n):
  su=max(0,su-a[i])
  com+=(su*a[i])%mod

print(com%mod)

Submission status: Accepted

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

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

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

print(ans % mod)

Submission status: Accepted

Solution code:
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
ruiseki = [A[i] for i in range(N)]

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    mod = 10 ** 9 + 7

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

    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
MOD = pow(10, 9) + 7
waru2 = pow(2, MOD-2, MOD)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    taikaku = 0
    for i in range(N):
        taikaku += pow(A[i], 2)
        taikaku %= MOD
    zennbu = 0
    sumA = sum(A)
    for i in range(N):
        zennbu += A[i]*sumA
        zennbu %= MOD
    
    ans = ((zennbu - taikaku) * waru2) % MOD
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

S = sum(A)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
elems = []
pref = []
raw = input().split(" ")
idx = 0
while(idx < n):
    elem = int(raw[idx]);
    elems.append(elem)
    if(idx == 0):
        pref.append(elems[idx])
    else:
        pref.append(pref[idx - 1] + elem)
    idx += 1

sum = 0
for idx in range(n):
    sum += elems[idx] * (pref[n - 1] - pref[idx])

print(sum%1000000007)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
from functools import reduce
S=reduce(lambda x,y:(x+y)%mod,A)
B=[]
for i in range(n):
    S=(S-A[i])%mod
    B.append(S)
N=0
for i in range(n):
    N=(N+A[i]*B[i])%mod
print(N)

Submission status: Accepted

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

Submission status: Accepted

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

for i in A:
    ruiseki.append(ruiseki[-1] + i)

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

A_acc = []
tmp = 0
for a in A:
	tmp += a
	tmp %= mod
	A_acc.append(tmp)

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

print(ans)

Submission status: Accepted

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

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

dot = sum(A)**2 % MOD
diag = sum(a**2 % MOD for a in A)
answer =  (dot - diag) * pow(2, -1, MOD) % MOD

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

MOD = int(1e9) + 7

N = int(input())
A = list(map(int, input().split()))
S = sum(A) % MOD

ans = 0

for a in A:
    ans += a * (S - a + MOD) % MOD
    ans %= MOD
div2 = (MOD + 1) // 2
print(ans * div2 % MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ret = 0
    sum_list = [None] * n + [0]
    for i in range(n-1, -1, -1):
        sum_list[i] = sum_list[i+1] + a[i]
    for i in range(n):
        ret += a[i] * sum_list[i+1]
        ret %= 1000000007
    print(ret)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 1000000007
n = int(input())
als = list(map(int, input().split()))

sumlist = [0 for _ in range(n)]
sumlist[0] = als[0]

for i in range(1, n-1):
    sumlist[i] = sumlist[i-1] + als[i]

ans = 0

for i in range(n-1):
    ans += als[n-1-i] * sumlist[n-2-i]
    ans = ans%mod

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))

    A_square_list = [A**2 for A in A_lsit]

    sum_A = sum(A_lsit)
    sum_A_square = sum(A_square_list)

    print( ((sum_A**2 - sum_A_square)// 2) % 1000000007 )

if __name__ == "__main__":
    main()

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve() :
    n = int(input())
    a = list(map(int, input().split()))
    a2 = [i ** 2 for i in a]

    print(((sum(a)**2 - sum(a2))//2)%(10**9+7))

if __name__ == "__main__" :
    solve()

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))

pref = [lst[0]]
for i in range(1, len(lst)):
    pref.append(pref[i-1]+lst[i])

ans = 0
for i in range(len(lst)):
    ans += lst[i] * (pref[-1] - pref[i])

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

Submission status: Accepted

Solution code:
n=input()
lst=list(map(int,input().split()))
m=sum(lst)%(10**9+7)
s=0
for i in lst:
    s=(s+i*i)%(10**9+7)
a=(m*m-s)%(10**9+7)
if a%2:print(a//2+5*10**8+4)
else:print(a//2)

Submission status: Accepted

Solution code:
n = int(input())

ls = list(map(int,input().split()))
mod = 10**9+7
acc = [0]

for a in ls:
  acc.append(acc[-1]+a)
  
ans = 0

for i in range(len(ls)-1):
  ans += ls[-i-1]*acc[-i-2]
  ans %= mod


print(ans)

Submission status: Accepted

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

MOD=10**9+7

sum1=0
for i in range(n):
    sum1+=a[i]
    sum1%=MOD

sum1*=sum1
sum1%=MOD
sum2=0
for i in range(n):
    sum2+=pow(a[i],2,MOD)
    sum2%=MOD

t = sum1-sum2
if t<0:
    t+=MOD

print((t)*pow(2,MOD-2,MOD)%MOD)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
a_c = list(itertools.accumulate(a))
MOD = 10**9 + 7
cnt = 0

for i in range(n):
    temp = a[i] * (a_c[-1] - a_c[i])
    cnt += temp

print(cnt % MOD)

Submission status: Accepted

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

ans=sum(A)%(2*(10**9+7))
ans=ans**2%(2*(10**9+7))

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

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

Submission status: Accepted

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

mo = 10**9 + 7
ans = 0
su = li[0]
for i in range(1,len(li)):
    ans += li[i]*su
    su+=li[i]
print(ans % mo)