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())
l = list(map(int,input().split())) 

totalsqr = (sum(l))**2

individualsqrsum=0
for i in l:
    individualsqrsum += i**2

ans = (totalsqr  - individualsqrsum)  // 2 
ans = ans%(10**9 + 7)
print(ans)

Submission status: Accepted

Solution code:
MOD = 1000000007

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

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

array_sum_square = pow(array_sum,2)

individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum+= pow(a[i],2)

ans=(array_sum_square - individual_square_sum) //2
print(ans%MOD)

Submission status: Accepted

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

print(result % m)

Submission status: Accepted

Solution code:
n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]
a_sum = sum(a_list)

total = 0
for i in range(0, len(a_list)-1):
    a_sum -= a_list[i]
    total += a_list[i] * a_sum
total = total % max
print(total)

Submission status: Accepted

Solution code:
from sys import stdin


def mod(val):
    res = val % (10 ** 9 + 7)
    if (res < 0):
        res += (10 ** 9 + 7)
    return res


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr_mod = [0] * len(A_arr)
    for i, a in enumerate(A_arr):
        A_arr_mod[i] = mod(a)

    ans = 0
    cache = sum(A_arr_mod)
    for i in range(N-1):
        cache -= A_arr_mod[i]
        ans += A_arr_mod[i] * cache
        ans = mod(ans)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A=list(map(int, input().split()))
B=[A[N-1]]
#print(B[0])
for i in range(len(A)-2):
    #print(i)
    b=B[i]+A[N-2-i]
    B.append(b)
#print(B)
total=0
for i in range(len(B)):
    total += A[i]*B[len(B)-1-i]

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ssum = sum(A)
ans = 0
for a in A:
    ssum -= a
    ans += a * ssum
    ans %= 1000000007

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
aa=list(map(int,input().split()))
b=0
c=0
for a in aa:
  b+=a
  c+=a**2
x=(b**2-c)//2
print(x%(10**9+7))

Submission status: Accepted

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

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

ans = ans % 1000000007
print(ans)

Submission status: Accepted

Solution code:
d = 10 ** 9 + 7
n = int(input())
lista = [int(x) for x in input().split()]
for k in lista:
    k %= d

totalJ = sum(lista)

total = 0
for i in range(n-1):
    totalJ -= lista[i]
    total += totalJ * lista[i]
total %= d
print(total)

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
S = list(accumulate(A))
mod = 1000000007

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

Submission status: Accepted

Solution code:
def resolve():
    numbers = int(input())
    number_list = list(map(int, input().split()))
    answer = 0
    num2 = sum(number_list)
    for num1 in number_list:
        num2 = num2 - num1
        answer += num1*num2
    print(answer%1000000007)
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    divider = 10 ** 9 + 7
    ans = 0
    total = sum(a)
    tmp = 0
    for i in range(n - 1):
        ai = a[i]
        tmp += ai
        ans = (ans + a[i] * (total - tmp)) % divider
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math

N = int(input())
An = [int(i) for i in input().split()]


mod = int(math.pow(10, 9) + 7)

sum_an = sum(An)
sum_result = 0

for i in range(N - 1):
    Ai = An[i]
    sum_an -= Ai
    sum_result += (Ai * sum_an) % mod


print(sum_result % mod)

Submission status: Accepted

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

ans = 0
s = 0

def mod(x):
    return int(x % int(1e+9 + 7))

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

    ans = mod(ans) 

print(int(ans))

Submission status: Accepted

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

# out = 0
# for i in range(n - 1):
#     for j in range(n - i - 1):
#         k = i + j + 1
#         # print(A[i], A[k])
#         out += (A[i] * A[k])
#         out %= mod
B = A[1:n]
B_s = 0
for i in range(n - 1):
    B_s += B[i] % mod

out = 0
for i in range(n - 1):
    out += A[i] * B_s
    out %= mod
    B_s -= A[i + 1]
    B_s %= mod
    if B_s < 0:
        B_s += mod

print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = 0
a = list(map(int, input().split()))
sum_tmp = sum(a[1:len(a)])
for i in range(len(a)-1):
  s += a[i] * sum_tmp
  sum_tmp -= a[i + 1]
print(s % 1000000007)

Submission status: Accepted

Solution code:
import numba
from numba import njit, b1, i4, i8, f8
import numpy as np  # noqa

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


def main(A):
    ans = 0
    s = 0
    for i in range(N - 2, -1, -1):
        s += A[i + 1]
        s %= 10**9 + 7
        ans = (ans + A[i] * s) % (10**9 + 7)
    return ans


print(main(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A_list = list(map(int,input().split()))
B_list = A_list[::-1]
C_list = list(accumulate(B_list))
D_list = C_list[::-1]
cnt = 0
for i in range(1,N):
    cnt += (A_list[i-1] * D_list[i]) % (10**9 + 7)

    if cnt >= (10**9 + 7):
        cnt -= (10**9 + 7)
print(cnt)

Submission status: Accepted

Solution code:

def solve():
    n=int(input())
    a=[0]+list(map(int,input().split()))
    b=[0]*(n+1)
    for i in range(1,n+1) :
        b[i]=b[i-1]+a[i]
    m=int(1e9+7)
    ans=0
    for i in range(1,n+1) :
        ans= (ans+a[i]*b[i-1])%m
    return ans

print(solve())

Submission status: Accepted

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

A=sum(a)%mod
total=0

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

print(total)

Submission status: Accepted

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

mod = 10 ** 9 + 7

summ = 0
quadsum = 0

for k in range(n):
    summ = (summ + A[k]) % mod
    quadsum = (quadsum + A[k]*A[k])%mod

ans = (summ*summ)%mod - quadsum
if ans % 2 == 1:
    ans += mod
ans = (ans/2)%mod
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0
r = 0
mod = 10**9+7
for i in range(n-1, 0, -1):
    r += a[i]
    t += a[i-1]*r
print(t%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-1):
    x = A[i]
    sumA -= x
    ans += sumA*x
print(ans%((10**9)+7))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def modinv(val, mod):
    b, u, v = mod, 1, 0
    while b:
        t = val // b
        val = val - t * b
        val, b = b, val
        u = u - t * v
        u, v = v, u
    u = u % mod
    return u


n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
total = 0
for item in a:
    total = (total + item) % mod

total = (total * total) % mod

for item in a:
    total = (total - (item * item)) % mod

print(total * modinv(2, mod) % mod)

Submission status: Accepted

Solution code:
MOD = 1000000007

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

array_sum = 0
for i in range(0, n, 1): 
    array_sum += a[i]
    #array_sum%=MOD

array_sum_square = pow(array_sum,2)

individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum+= pow(a[i],2)
    #individual_square_sum%=MOD

ans=(array_sum_square - individual_square_sum) //2
print(ans%MOD)

Submission status: Accepted

Solution code:
def input_one_number():
    return int(input())
 
def input_multiple_number():
    return map(int, input().split())
 
def input_multiple_number_as_list():
    return list(map(int, input().split()))
MOD=1000000000 + 7
ans=0
a_min=0

n=input_one_number()
a=input_multiple_number_as_list()
a_sum=sum(a)
for i in range(n):
    a_min+=a[i]
    ans+=a[i]*(a_sum-a_min)
    ans=ans%MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
tokens = itertools.chain.from_iterable(map(str.split, sys.stdin))

mod = 1000000007
n = int(next(tokens))
a = [int(next(tokens)) % mod for _ in range(n)]

sms = []
sma = sum(a)
for i in range(n):
    sma -= a[i]
    sms.append(sma)
#print(sms)

m = 0
for i in range(n - 1):
    sm = sms[i]
    #print(i, a[i], sm)
    m = (m + a[i] * sm) % mod

print(m)

Submission status: Accepted

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

ans = 0

a_goketi = sum(a)
b = []

for i in range(n):
    b.append(a_goketi - a[i])
    a_goketi -= a[i]

    ans += a[i] * b[i] 

ans %= 1000000007
print(ans)

Submission status: Accepted

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

total = 0
left = 0
sum = sum(A)
#print(end)

for i in range(N - 1):
    #print(i, A[i])
    left = left + A[i]
    #start = i + 1
    #for j in range(start, N):
        #print(i, j)
        #sum = sum + A[j]
    #print(A[i], sum)
    right = sum - left
    #print(i, left, right, A[i])
    total = (total + A[i] * right) % 1000000007

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    A  = [int(i) for i in input().split()]
    #N = 100000
    #A = [i for i in range(1,100000)]
    sum_a = sum(A)% 1000000007
    ans = 0
    for i in range(N):
        sum_a = (sum_a - A[i])% 1000000007
        ans = (ans + sum_a*A[i] ) % 1000000007
        #print((sum_a-A[i])*A[i]/2 ,ans)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

s1 = sum(A) ** 2
s2 = sum([x ** 2 for x in A])
ans = (s1 - s2) // 2 % 1000000007
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

ans = 0
aa = 0
for i in range(n-1):
    aa += a.pop()
    # print(a,aa)
    ans +=  (aa * a[-1]) % mod
    ans %= mod

print(ans%mod)

Submission status: Accepted

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read
MOD = 10**9 + 7

n = int(input())
a = np.array(readline().split(), dtype=np.uint64)
r = np.cumsum(a[::-1])[::-1]
r %= MOD
x = a[:-1] * r[1:]
x %= MOD
ans = np.sum(x) % MOD
print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
B = [0]*N

for i in range(N):
  A[i] = int(A[i])
  B[i] = A[i]*A[i]

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

Submission status: Accepted

Solution code:
# C

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

sumA = sum(A)

sumA_2 = sum([a**2 for a in A])

print(((sumA**2-sumA_2)//2)%p)

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:
N = int(input())
Ai = list(map(int, input().split()))

gokei = 0
now_sum = sum(Ai)

for i in Ai:
    now_sum -= i
    gokei += i * (now_sum)

print(gokei % 1000000007)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

MOD = 10 ** 9 + 7

tmp = 0
for a in A[1:]:
    tmp += a
    tmp %= MOD

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

    tmp -= A[i + 1]

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
aL = list(map(int, input().split(" ")))

MOD = 10**9 + 7

aL2 = [aL[-1]]
for a in reversed(aL[:-1]):
    aL2.append((aL2[-1] + a) % MOD)
aL2 = list(reversed(aL2))

ans = 0
for i in range(n - 1):
    ans += aL[i] * aL2[i + 1]
    ans %= MOD

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
from itertools import combinations
N=int(input())
A=list(map(int,input().split()))

zen=sum(A)


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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
r = [0] * (n + 1)
for i, v in enumerate(a, start=1):
    r[i] = v + r[i - 1]

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    total_sum = 0
    inv_cum_sum = []
    ans = 0 
    for i in range(len(A)):
        total_sum += int(A[i] % int(1e9+7))
        total_sum = int(total_sum % int(1e9+7))
    tmp_cum_sum = 0
    for i in range(len(A)):
        tmp_cum_sum += int(A[i] % int(1e9+7))
        tmp_cum_sum = int(tmp_cum_sum % int(1e9+7))
        inv_cum_sum.append(total_sum - tmp_cum_sum)
    for i in range(len(inv_cum_sum)):
        ans += int((A[i] * inv_cum_sum[i]) % int(1e9+7))
    print(int(ans % int(1e9+7)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    mylist = LI()
    shift = 1000000007
    S = sum(mylist)
    res = 0
    
    for i in mylist:
        S-=i
        if S==0:
            break
        res += (S*i)%shift
    

    print(int(res % shift))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 1000000007

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    s = sum(A)
    for i in range(N - 1):
        s -= A[i]
        ans += A[i] * s
    print(ans % mod)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split())) + [0]
B = [0]*(N+1)

for i in range(N-1):
    B[N-i-1] = A[N-i-1]+B[N-i]
ans = 0
MOD = 10**9 + 7

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

Submission status: Accepted

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

out = (sum(As)**2 - sum([a**2 for a in As]))//2
print(out % (10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10**9 + 7
sum_modA = 0
for a in A:
    sum_modA = (sum_modA + a) % mod

sum_mul = sum_modA**2 % mod
for a in A:
    sum_mul = (sum_mul - a**2 % mod) % mod

sum_mul = sum_mul * pow(2, mod - 2, mod) % mod

print(sum_mul)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n, *a = map(int, read().split())
    large_p = 10 ** 9 + 7
    aac = tuple(accumulate(a))
    r = 0
    for i1 in range(n):
        t1 = aac[-1] - aac[i1]
        r += (t1 * a[i1]) % large_p
    r = r % large_p
    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
def solver(N,A):
    powsum = sum([i ** 2 for i in A])
    return (sum(A) ** 2 - powsum) // 2 % 1000000007
print(solver(N,A))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
M = 1000000007
sm = 0
for i in l:
	sm = (sm + i)
sms = pow(sm,2)
ss = 0
for i in range(n):	
	ss = (ss + (l[i] * l[i]))
print(((sms - ss)//2)%M)

Submission status: Accepted

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

wa = 0
wa_list = []
for i in range(N)[::-1]:
    if i == 0:
        break
    wa += A[i]
    wa_list.append(wa)

wa_list.reverse()
ans  = 0
for i in range(N-1):
    seki = A[i]*wa_list[i]
    ans += seki

print(ans % mod)

Submission status: Accepted

Solution code:
N = int(input())
MOD = 1000000007
A =  list(map(int,input().split()))
cum = [0]*(N+1)
for i in range(N):
    cum[i+1] = cum[i] + A[i]
    cum[i+1] %= MOD

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    n = int(input())
    a_s = list(map(int, input().split()))

    # 和
    aaa = sum(a_s)

    ans = 0
    for cnt, a in enumerate(a_s):
        aaa -= a
        if aaa == 0:
            break

        ans += aaa * a
        ans = ans % (pow(10, 9) + 7)

    print(ans % (pow(10, 9) + 7))

    # テストクラス


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 3"""
        output = """11"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """4
141421356 17320508 22360679 244949"""
        output = """437235829"""
        self.assertIO(test_input, output)

    # 自作テストパターン
    def test_original(self):
        pass


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

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

ans = 0
SUM = sum(ls)
for i in range(len(ls)):
    SUM -= ls[i]
    ans += ls[i] * SUM
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())

mod = 10**9 + 7

A = [int(i)%mod for i in input().split()]

S = [0]*N

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

print(ans%mod)

Submission status: Accepted

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

AA = 0
ans = 0
for a in A:
    AA = (AA + pow(a, 2, MOD))%MOD
    ans = (ans + a%MOD)%MOD
inverse2 = pow(2, MOD-2, MOD)
ans = (((pow(ans, 2, MOD) - AA%MOD)%MOD)*inverse2)%MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
	
suffS = []
lst = lst[::-1]
summ = 0
for i in lst:
	suffS.append(summ)
	summ += i
res = 0
for i in range(n):
	res += suffS[i] * lst[i]
	res %= (10**9+7)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 1000000007
N = int(input())
A = list(map(int, input().split()))
c = 0
S = 0
for a in A:
  S += a % MOD
  S %= MOD
for i in range(N):
    c += (A[i] % MOD) * ((S - A[i] % MOD) % MOD)
    c %= MOD
mod = pow(2, -1, 1000000007)
c = c * mod
c %= MOD
print(int(c))

Submission status: Accepted

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

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

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

sum %= mod
print(sum)

Submission status: Accepted

Solution code:
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    temp=int(array_sum_square - 
            individual_square_sum) 
    temp=temp//2
    return temp%1000000007








n = int(input())
l = list(map(int, input().split()))
print(findProductSum(l,n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
an = [int(num)  for num in input().split()]

an_total = sum(an)
answer = 0
for i in range(len(an)-1):
  an_total -= an[i]
  answer +=  an[i] * an_total
print(answer%1000000007)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def f(l):
    global ans
    half = len(l) // 2
    left = sum(l[:half])
    left %= MOD
    right = sum(l[half:])
    right %= MOD
    ans += left * right
    ans %= MOD
    if len(l) < 2:
        return
    f(l[:half])
    f(l[half:])
ans = 0
f(a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop, heapify
import math
import itertools as it
from collections import deque 


def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------


mod = 10**9 + 7

N = inp()
A = inpl()
wa = 0
sm = A[0]
for i in range(1, N):
    wa = (wa + sm * A[i]) % mod
    sm = (sm + A[i]) % mod
print(wa)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
ans=0
mod=1000000007
sql=(sum(l))**2
for i in l:
    ans+=i*i
print((sql-ans)//2%mod)

Submission status: Accepted

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

Submission status: Accepted

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

modx=10**9+7
suma=sum(a)
sumx=0
for i in range(n-1):
  suma-=a[i]
  sumx=(sumx+ a[i]*suma)%modx
    
print(sumx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
total = 0
sum_sqr = 0
sqr_sum = 0
for i in range(n):
    sum_sqr = (sum_sqr + a[i])
sum_sqr = (sum_sqr * sum_sqr)
for i in range(n):
    sqr_sum = (sqr_sum + ((a[i] * a[i])))
# print(sqr_sum, sum_sqr)
total = (sum_sqr - sqr_sum) // 2
print(total%mod)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
# t, s = map(str,input().split())

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

a = []
for i in range(len(str_a)):
    a.append(int(str_a[i]))

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

print(total % (1000000007))

Submission status: Accepted

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

total = 0

for i in range(n):
    total = total + a[i]
ts = total * total

iss = 0

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

Submission status: Accepted

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

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

Submission status: Accepted

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

for i in range(N-1):
    c+= A[i]* (sumA-A[i])
    sumA-= A[i]
print(c%(10**9+7))

Submission status: Accepted

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

'''
a b c d e

ab + ac + ad + ae + bc + bd + be + cd + ce + de
=
a(b+c+d+e) + b(c+d+e) + c(d+e) + d(e)
=
(a+b+c+d)e + (a+b+c)d + (a+b)c + a(b)
'''
l = 0
s = 0
for i in range(n-1):
    l += a[i]
    s += l*a[i+1]
    s %= 1000000007
print(s)

Submission status: Accepted

Solution code:
import collections

n = int(input())

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

q = collections.deque(a)

retu = sum(a)
ans = 0

for i in range(n):
    nowA = q.popleft()
    retu -= nowA
    ans += (nowA * retu)

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

Submission status: Accepted

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

base = int(1e9+7)
tot = 0

s = 0
for a in A:
    tot += s*a
    s += a
    tot %= base

print(tot)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
#a = [100]*N
A = dict(zip(list(range(len(a))),a))
ans = 0
suma = 0
suma = sum(a)

for i in range(len(a)-1):
  suma -= A[i]
  ans = (ans + A[i]*suma)%1000000007
  
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
K = sum(A)
S = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
import collections
import itertools

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

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

    print(ans%MOD)

resolve()