Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).

Constraints

2 \leq N \leq 2\times 10^5

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

11

We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11.

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
mod=10**9+7
S=sum(a)%mod
T=sum([i*i for i in a])%mod
print((pow(2,mod-2,mod)*(S*S-T))%mod)

Submission status: Accepted

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

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

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

ans = ans % mod
print(ans)

Submission status: Accepted

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

ans = 0
s = sum(A)
for i, x in enumerate(A):
	s -= x
	ans += s * x
	ans %= 10 ** 9 + 7

print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
m = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
x = 0
s = [x := x + c for c in a]
ans = 0

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

Submission status: Accepted

Solution code:

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

    Acc = [0] + list(accumulate(A))

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

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
mod = 1000000007

n = int(input())
a = list(map(int, input().split(' ')))
b = [0] * (n + 1)

for i, v in enumerate(a):
    b[i+1] = (b[i] + v) % mod

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

print(ans)

Submission status: Accepted

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

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):
    s -= A[i]
    ans += (A[i] * s) % mod

print(ans%mod)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    MOD = 10 ** 9 + 7
    
    sum_a = sum(A)
    ans = 0
    for ai in A:
        sum_a -= ai
        ans += ai * sum_a
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

import sys
input=sys.stdin.readline

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
ans=sum(arr)*sum(arr)
for val in arr:
    ans-=(val*val)%mod
print((ans*pow(2,-1,mod))%mod)

Submission status: Accepted

Solution code:
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()

# print(n)
# print(a)
b = 0
ans = 0
for i in a:
    i %= 10**9+7 
# print(a)

s = sum(a)
s2 = sum(map(lambda x:x**2,a))

ans = (s**2 - s2 ) // 2

ans %= (10**9+7)

print(ans)

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(A[i]+S[i-1])

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

print(_sum)

Submission status: Accepted

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

all_a = 0

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

for i in range(n):
    all_a = all_a - a[i]
    number = number + (a[i] * all_a)
    number = number % mod
amari = number % mod
print(amari)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
A = list(map(int,input().split()))
allsum = 0
sums_list = deque()
sums = 0
for i in range(N-1, 0, -1):
  sums = (sums + A[i]) % (10**9 + 7)
  sums_list.appendleft(sums)
for i in range(N-1):
  allsum = (allsum + A[i] * sums_list[i]) % (10**9 + 7)
print(allsum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_ = list(map(int, input().split()))
A = []
mod = 10 ** 9 + 7
for i, a_ in enumerate(A_[::-1]):
    if i == 0:
        A.append(a_ % mod)
    else:
        a = (a_ + A[-1]) % mod
        A.append(a)
A = A[::-1]
A = A[1:]
ans = 0
for i, a in enumerate(A_[:-1]):
    ans += A[i] * a % mod
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys
 
def main():
    def input():return sys.stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split(" ")))
 
    mod = 10**9+7
    res = 0

    S = sum(A)
    S2 = sum(map(lambda x: x**2, A))
    print((S**2-S2) // 2 % mod)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc177_C_6_retry_累積和を使用する
int_n = int(input())
list_tmp = list(map(int, input().split()))
 
int_sum = 0
int_divide = (10**9) + 7
int_sum_tmp = sum(list_tmp)

for i in range(0, len(list_tmp) - 1):
  int_sum_tmp = int_sum_tmp - list_tmp[i]
  int_sum = int_sum + (int_sum_tmp * list_tmp[i])
print(int_sum % int_divide)
#  for j in range(i + 1, len(list_tmp)):
#    if list_tmp[i] >= int_divide:
#      list_tmp_i = list_tmp[i]%int_divide
#    else:
#      list_tmp_i = list_tmp[i]
#      
#    if list_tmp[j] >= int_divide:
#      list_tmp_j = list_tmp[j]%int_divide
#    else:
#      list_tmp_j = list_tmp[j]    
#    
#    int_sum = int_sum + (list_tmp_i*list_tmp_j)
#    
#    if int_sum >= int_divide:
#      int_sum = int_sum%int_divide
#      
#print(int_sum)

Submission status: Accepted

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

s = sum(A)
S = s**2
D = sum([a**2 for a in A])

print(int((S - D) // 2) % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
A = list(map(int,input().split()))

mod = 1000000007
sm = 0

for i in range(N):
    sm += A[i]
    sm %= mod
    
ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(int(res))

Submission status: Accepted

Solution code:
n = int(input())

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

sigma = sum(a)
count = 0
for i in range(len(a)-1):
  start = a[i]
  sigma = sigma-a[i]
  count = count + start * sigma
  if count >= 10**9+7:
    count = count % (10**9+7)

print(count)

Submission status: Accepted

Solution code:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)

Submission status: Accepted

Solution code:
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()

# print(n)
# print(a)
b = 0
ans = 0
for i in a:
    i %= 10**9+7 
# print(a)

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

ans %= (10**9+7)

print(ans)

Submission status: Accepted

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

S = [0]
sum =0
for i in range(0, N):
    S.append(S[i] + A[i])
for i in range(N):
    sum = sum + (S[i+1]-A[i]) * A[i]
print(sum%1000000007)

Submission status: Accepted

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

Sum = sum(A)
ans = 0
for i in range(N):
  Sum = Sum-A[i]
  AA = Sum*A[i]
  ans += AA
  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) % MOD
ans = (S ** 2) % MOD
for a in A:
    ans -= a**2
    ans %= MOD

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_sum = sum(a)
aa = np.array(np.cumsum(a),dtype="object")
all_a = sum(a)

mod = 1000000007

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

print(ans%mod)

Submission status: Accepted

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

sq_sum_a = sum(a)**2
sum_sq_a = sum(map(lambda x: x**2, a))

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_sum = sum(a)
aa = np.array(np.cumsum(a),dtype="object")
all_a = sum(a)

mod = 1000000007

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

print(ans%mod)

Submission status: Accepted

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

sum = sum(A)
result = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = input()
a = np.array(list(map(int, input().split())), dtype=object)
print((sum(a)**2 - sum(a**2)) // 2 % (10 ** 9 + 7))

Submission status: Accepted

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

ans = 0

ans = sum(nums) * sum(nums) - sum([num*num for num in nums])

print((ans // 2) % mod)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

total=sum(alst)
sum=0

# for i in range(n-1):
#   for j in range(i+1,n):
#     sum=pow(sum+alst[i]*alst[j],1,MOD)

# print(sum)

for a in alst:
  sum = sum+a * (total - a)
  sum %= MOD

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

Submission status: Accepted

Solution code:
mod = 1000000007
N = int(input())
A = list(map(lambda x: int(x) % mod, input().split(" ")))

"""
累積話を計算しておく: O(N)
"""
_sum = 0
for i in range(N):
    _sum += A[i]
    _sum %= mod

"""
1重ループ内で下記を行う: O(N)

- 端のブロックを累積和から崩す（減算）
- 端のブロックと累積和をかける
- modをとる
"""
ans = 0
for i in range(N):
    # 累積和の端のブロックを崩す
    _sum -= A[i]

    ans += A[i] * _sum
    ans %= mod

print(ans)

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    M = 10 ** 9 + 7

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


main()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0]*(n+1)
    MOD = 10**9 + 7

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




    


if __name__ == '__main__':
    main()

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))
print((s**2-s2)//2 % (10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-29 22:18
# @url:https://atcoder.jp/contests/abc177/tasks/abc177_c
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    a=list(map(int,input().split()))
    prefix=[a[0]]
    mod=10**9+7
    for i in range(1,len(a)):
        temp=prefix[-1]%mod+a[i]%mod
        prefix.append(temp%mod)
    s=0
    for i in range(len(a)-1):
        s=s+a[i]*(prefix[-1]-prefix[i])
        s=s%mod
    print (s)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
cum=[0]*n
mod=10**9+7
cum[0]=arr[0]%mod

for i in range(1,n):
    cum[i]=cum[i-1]+arr[i]
    cum[i]%=mod

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
val = sum(a[1:])

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_sum = 0
s = []
ans = 0

for i in range(n):
    a_sum += a[i]
    s.append(a_sum)

for i, j in enumerate(a):
    ans += j * (s[n - 1] - s[i])

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [i % (10**9 + 7) for i in a]
val = sum(a[1:])

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype = 'object')
mod = 10**9 + 7

sq_sum_a = sum(a)**2
sum_sq_a = sum(a**2)

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod
# xy = ((x + y)**2 - (x**2 + y**2)) // 2

print(ans)

Submission status: Accepted

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

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

print(ans % MOD)

Submission status: Accepted

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

for i in range(n-1):
    ans += a[i] * s[n-2-i] % MOD

ans = ans % MOD

print(ans)

Submission status: Accepted

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

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

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

ans = ans % MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

mod=1000000007
S=0
sl=0

for i in range (N):
    sl+=A[i]
    sl%=mod
    
for j in range(N):
    sl-=A[j]
    if sl<0:
        sl+=mod
    S+=A[j]*sl
    S=S%mod

print(S)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = 0
sum_n = [0]*n
sum_n[0] = l[0]
sumall = sum(l)
for i in range(1,n):
    sum_n[i] = sum_n[i-1] + l[i]
for i in range(n):
    ans += ((l[i]*(sumall-sum_n[i]))%1000000007)
print(ans%1000000007)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(s) for s in input().split()]
ans = int(0)
temp = int(0)
MOD = int(1000000007)
sumari = sum(a)

for i in range(N-1):
  sumari = sumari - a[i] 
  temp = sumari % MOD
  temp = temp * a[i]
  temp = temp % MOD
  ans += temp
  ans = ans % MOD
print(ans)

Submission status: Accepted

Solution code:

n = int(input())
item = [int(i) for i in input().split()]
mod = 10**9+7
t = (sum(item)**2 - sum([i**2 for i in item]))

print(int(t * pow(2, -1, mod)) % mod)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
Sum = sum(A)
square_sum = sum(map(lambda x:x*x, A))
print((Sum*Sum - square_sum)//2%(10**9+7))

Submission status: Accepted

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

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

    ans+=temp
print((ans//2)%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(T) for T in input().split()]
SumA = [0]*(N+1)
for TN in range(0,N):
    SumA[TN+1] = SumA[TN]+A[TN]
Sum = 0
Mod = 10**9+7
for TA in range(1,N):
    Sum += (A[TA]*SumA[TA])%Mod
print(Sum%Mod)

Submission status: Accepted

Solution code:
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
wa = []
total = 0
for i in reversed(range(1, len(an))):
    total = total + an[i]
    wa.append(total)
wa = sorted(wa, reverse=True)
ans = 0
for i in range(0, n-1):
#     print(an[i] * wa[i])
    ans = ans + an[i] * (wa[i]%m)
    ans = ans % m
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
S = 0
T = 0
for i in range(N):
  S += As[i]
  T += (As[i] * As[i]) % 1000000007
# print(S)
# print(T)
A = S*S % 1000000007
B = T % 1000000007
X = (A - B) % 1000000007

print((X * int((1000000007 + 1)/2)) % 1000000007)

Submission status: Accepted

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

Submission status: Accepted

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

mod = (10**9 + 7)
ans = 0

import numpy
alistsum = numpy.cumsum(alist)
asum = sum(alist)

for i in range(n-1):
    ans += alist[i]*(asum - alist[i])
    asum -= alist[i]
    ans = ans%mod
print(ans)

Submission status: Accepted

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = [int(x) for x in input().split()]
s = sum(seq[1:])
ans = 0
m = 10**9 + 7
for i in xrange(n-1):
    ans = (ans + (seq[i] * s)) % m
    s -= seq[i+1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7

s = sum(A)** 2

a = 0
for i in A:
    a += (i ** 2)

ans = (s - a) // 2
ans = ans % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)

Submission status: Accepted

Solution code:
MOD=10**9+7

N=int(input())
A=list(map(int,input().split()))
S=sum(A)**2%MOD
for i in range(N):
    S=(S-A[i]**2+MOD)%MOD
print(S*pow(2,MOD-2,MOD)%MOD)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
k = 0
num = sum(a)
import math

for i in range(n):
    reje = num - a[i]
    k += reje * a[i]

x = k//2
t = 10 ** 9 + 7
ans = x % t
print(ans)

Submission status: Accepted

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

sum = 0
for i in a:
    sum += i

sum = sum * sum

for j in a:
    sum = sum - j*j

sum = (sum // 2) % 1000000007 
print(sum)

Submission status: Accepted

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

sm = sum(A)

ans = 0
for s in range(len(A)-1):
    #ans += A[s]*sum(A[s+1:])
    sm -= A[s]
    ans += A[s]*sm

print(ans%mod)

Submission status: Accepted

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力を取得
    N = int(input())
    A = list(map(int, input().split()))

    return N, A


def main(N: int, A: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 整数(2 <= N <= 2 * 10**5)
        A (list): 整数(0 <= A_i <= 10**9)
    """
    # 求解処理
    mod = 10**9 + 7
    ans = 0
    sum_A_j = sum(A)
    for i in range(N):
        A_i = A[i]
        sum_A_j -= A_i
        ans += A_i * sum_A_j
        ans %= mod

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, A = get_input()

    # メイン処理
    main(N, A)

Submission status: Accepted

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

MOD = 1000000007

a = 0
b = 0
for i in range(N):
    a += A[i] % MOD
    b += (A[i] ** 2) % MOD
a = a ** 2
ans = (a - b) * pow(2, MOD - 2, MOD) % MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
input = stdin.readline
n = input().rstrip()
n = int(n)
a = list(map(int, input().split()))
a = np.array(a)
suma = np.cumsum(np.array(a))

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

print(ans)

Submission status: Accepted

Solution code:
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))
mod = 10**9 + 7

n = ri()
a = rl()
s = sum(a)
ans = 0
for i in a:
    s -= i
    ans = (ans + s*i)%mod
print(ans)

Submission status: Accepted

Solution code:
import itertools as itr

a = int(input())
p = list(map(int,input().split()))
mod = 10**9 + 7
ans =0
sum_list = list(itr.accumulate(p))
for i in range(len(p)-1):
    o = p[i+1]
    w =sum_list[i]
    ans = (ans+o*w%mod)%mod
print(ans)

Submission status: Accepted

Solution code:
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

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

ans = 0
acc = 0
for i in A:
    ans += i * acc
    acc += i
    ans %= MOD
    acc %= MOD

print(ans)

Submission status: Accepted

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

k = 1000000007

sm = sum(A)

ans = 0
for s in range(len(A)-1):
    #ans += A[s]*sum(A[s+1:])
    sm -= A[s]
    ans += A[s]*sm

if ans>1000000007:
    print(ans%k)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

    ans = int(ans % mod)
    print(ans)
 
resolve()