Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

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

Constraints

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

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
1 2 3

Sample Output 1

11

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

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
A = readInts()
cum = list(accumulate(A))
ans = 0
for i in range(n-1):
    ans += A[i] * (cum[n-1]-cum[i])
    ans%=mod
print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(ans)

Submission status: Accepted

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

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

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

print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = 0
res = 0
m = 10**9+7
for ai in a:
  res += (s * ai) % m
  s += ai

print(res % m)

Submission status: Accepted

Solution code:
import numpy as np
MOD = 10**9+7

N = int(input())
A = np.array(list(map(int, input().split())))
A = A % MOD

AS = []
s = 0
for a in range(len(A)):
  s = (s + A[a]) % MOD
  AS.append(s)
AS = np.array(AS)

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

Submission status: Accepted

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

M = 10 ** 9 + 7
T = sum(map(lambda x: x**2, A))
print (((sum(A)**2-T)//2)%M)

Submission status: Accepted

Solution code:
input();m=10**9+7;s=sum(A:=[*map(int,input().split())]);print(((s*s-sum(a**2for a in A))//2)%m)

Submission status: Accepted

Solution code:
n=int(input())

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

summ=0

for i in l:
	summ+=i

ans=0
for i in l:
	summ-=i
	ans+=i*summ

print(ans%1000000007)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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


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

Submission status: Accepted

Solution code:
import itertools


def main():
    count = 0
    MOD = 10**9+7
    n = int(input())
    a = list(map(int, input().split()))
    s = [0]
    for i in range(n-1):
        s.append((s[i]+a[i]) % MOD)
    for ai, si in zip(a, s):
        count += (ai*si) % MOD
    return count % MOD


if __name__ == "__main__":
    print(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])

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

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

Submission status: Accepted

Solution code:
"""C."""

import sys

input = sys.stdin.readline  # noqa: A001

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

MOD_VALUE = 10**9 + 7
result = 0

a_sum = sum(a)

for v in a:
    result += v * (a_sum - v)
    a_sum -= v

if result < MOD_VALUE:
    print(result)
else:
    print(result % MOD_VALUE)

Submission status: Accepted

Solution code:
"""C."""

import sys

input = sys.stdin.readline  # noqa: A001

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

MOD_VALUE = 10**9 + 7
result = 0

a_sum = sum(a)

for i, v in enumerate(a):
    result += v * (a_sum - v)
    a_sum -= v

if result < MOD_VALUE:
    print(result)
else:
    print(result % MOD_VALUE)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# n=3
# ai = np.array([1, 2, 3])

# ai = ai[np.newaxis, :]
# 
# ai2 = ai.T.dot(ai)
# ai2u = np.triu(ai2, k=1)
# 
# s = ai2u.sum()


l = len(ai)

integ = [ai[0]] * len(ai)
for i in range(1, len(ai)):
    integ[i] = integ[i-1] + ai[i]

s = 0
for j in range(l):
    this_s = integ[-1] - integ[j]
    s += ai[j] * this_s

ans = s % (1000000000 + 7)

print(ans)

Submission status: Accepted

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

for ai in al:
    ans -= ai**2

print((ans//2)%mod)

Submission status: Accepted

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

S=sum(A)
a=0
for x in A:
  S-=x
  a+=S*x
    
MOD=10**9+7
print(int(a%MOD))

Submission status: Accepted

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

sum_list = sum(A)
sum_of_product = 0

for i in A:
    sum_list -= i
    sum_of_product = ((sum_list * i) % (10 ** 9 + 7) + sum_of_product) % (10 ** 9 + 7)

print(sum_of_product)

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
sum=sum*sum

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

ans=(sum-s)//2
ans%=J
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

mod = 10**9 + 7

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    prefix = [a[0]]
    for i in range(1,n):
        prefix.append(prefix[i-1] + a[i])
    ans = 0
    for i in range(n-1):
        d = (a[i]*(prefix[-1] - prefix[i]))%mod
        ans = ans + d
        ans = ans%mod
    print(ans)

Submission status: Accepted

Solution code:

mod10_9p7 = 10**9 + 7

def main() :

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

    sop = [0] * (n-1)
    sop[0] = a_list[0]

    for i in range(1,n-1):
        a = a_list[i]
        sop[i] = sop[i-1] + a

    # print(sop)

    res = 0
    # res = (a_list[0] * a_list[1]) % mod10_9p7
    for i in range(n-1) :
        res += (a_list[i+1] * sop[i]) % mod10_9p7
        res = res % mod10_9p7
    
    print(res)
        

main()

Submission status: Accepted

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

for i in range(len(a)):
    b -= a[i]
    sum += a[i]*b   

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

Submission status: Accepted

Solution code:
num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
temp_sum = 0
for j in range(num):
	temp_sum += num_list[j]

for i in range(num):
	num_a = num_list[i]
	temp_sum -= num_a
	sigma += num_a * temp_sum


sigma %= law
print(sigma)

Submission status: Accepted

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

sq = 0
for i in range(n):
  sq += L[i]**2

tmp = (pow(sum(L),2) - sq) // 2
print(tmp % (pow(10,9)+7))

Submission status: Accepted

Solution code:
N = int(input()) #入力する整数
A = list(map(int,input().split())) #入力する数列A
SUMA = sum(A) #数列の和
MOD = 10**9 + 7 # mod
C = [0] * (N-1) #累積和数列
for i in range(N-1): #\sum_{j = i+1}^{N}を求めて数列に代入する
  SUMA -= A[i]
  C[i] = SUMA
ans = 0 #求める答え
for i in range(N-1):
  ans += A[i]*C[i]
  ans %= MOD #その都度modで割った余りにする
print(ans) #答えを出力する

Submission status: Accepted

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

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

print(ans % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    ans -= a[i]**2
ans //= 2
print(ans%mod)

Submission status: Accepted

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

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

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

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

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    A = LII_split()

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

        # 2乗は死ぬので累積和を使う（使えることは式を書き出せばわかる）
        # for j in range(i + 1, N):
        #     s += As[j] * As[i]
        if s > 10 ** 9 + 7:
            s %= 10 ** 9 + 7

    print(s)
    
resolve()

Submission status: Accepted

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

partial_sum = 0
sum_ = 0
for i in range(1, N):
  partial_sum += a_list[i-1]
  sum_ += a_list[i] * partial_sum
  
print(sum_ % (10 ** 9 + 7))

Submission status: Accepted

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

ans = 0
cumsum = 0

for i in range(n-1):
    cumsum += A[n-i-1]
    ans += (A[n-i-2] * cumsum)
    ans %= 1000000007

print(ans)

Submission status: Accepted

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

sumA = sum(A)
sumB = 0
sumC = sumA

for i in range(n):
    sumC = sumC- A[i]
    sumB += A[i] * sumC

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

Submission status: Accepted

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

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

      

print(sum%1000000007)

Submission status: Accepted

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

mod = 10**9 + 7
total =sum(an)
ans = 0
z = an[0]

for x in range(n-1):
  nokori = total-z
  ans += an[x] * nokori % mod
  z += an[x+1]

    
ans = ans % mod    
print(ans)

Submission status: Accepted

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

#累積和のリストを作成
S = [0]*(N+1)
ans = 0
for i in range(N):
    S[i+1] = A[i] + S[i]%mod

#累積和って感じですね
for i in range(N):
    sum = S[N] - S[i + 1]
    if sum < 0:
        sum += mod
    ans += A[i] * sum

print(ans % mod)

Submission status: Accepted

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

sumA = sum(A)
ans = 0
for i in range(len(A)-1):
    sumA -= A[i]
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sumA % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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 %= 10**9+7
print(ans)

Submission status: Accepted

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

ans = 0
for i in A:
  s -= i
  ans += i * s

  
print(ans % MOD)

Submission status: Accepted

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

n = int(input())

arr = [int(i) for i in input().split(' ')]

parr = [0]*n

parr[n-1] = arr[n-1]

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

for j in range(n-2, -1, -1):
    parr[j] = arr[j] + parr[j+1]

    ans += arr[j] * parr[j+1]
    ans = ans % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
mod = 10**9+7
ls = list(map(int,input().split()))
di = [i**2 for i in ls]
print((((sum(ls)**2)-(sum(di)))//2)%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
N=int(input())
K=[int(n) for n in input().split()]
S=sum(K)
total=0
for i in range(N):
  S-=K[i]
  total+=K[i]*S
print(total %(10**9+7))

Submission status: Accepted

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

sum = sum(a) - a[0]

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

Submission status: Accepted

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

s = 0
r = [0] * N
r[0] = a[0]

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

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

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

Submission status: Accepted

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

zt=sum(A)**2
for _ in A:
  zt -= _**2
  
zt=(zt//2)%ao
print(zt)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

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

print(ans)

Submission status: Accepted

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

total = sum(numbers)

m = 10 ** 9 + 7
result = 0
for number in numbers[:-1]:
  total -= number
  result += (total * number)
  result %= m
 
print(result)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[0] = a[0]

# 累積和の計算
for i in range(1, n):
    dp[i] = (a[i] + dp[i - 1]) % mod

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

print(ans)

Submission status: Accepted

Solution code:
# C - Sum of product of pairs
from itertools import accumulate


def main():
    N, *A = map(int, open(0).read().split())
    rev_cumsum = list(accumulate(reversed(A[1:])))[::-1]
    MOD = 10 ** 9 + 7
    res = sum(a * c for a, c in zip(A[:-1], rev_cumsum)) % MOD
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
temp = sum(a)**2
for x in a:
	temp -= x**2
print((temp//2)%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 a:
  s -= i
  s %= mod
  ans += s*i
  ans %= mod
  
print(ans)

Submission status: Accepted

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

y = 0
for i in range(n):
    y += a[i]
    y = y % (2 * p)
x = (y ** 2) % (2 * p)

w = 0
for i in range(n):
    w += ((a[i] ** 2) % (2 * p))
    w = w % (2 * p)

z = ((x - w) / 2) % p
print(int(z))

Submission status: Accepted

Solution code:
mod = 1000000007
N = int(input())
A = list(map(int, input().split()))
S = [0] # 累積和のリスト
ans = 0
for i in range(N):
    S.append(A[i] + S[i] % mod)
for i in range(N):
    sum = S[N] - S[i + 1]
    if sum < 0:
        sum += mod
    ans += A[i] * sum
print(ans % mod)

Submission status: Accepted

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

sum_num = 0
sum_temp = sum(int_list[1:])

for i in range(N-1):
  sum_num += int_list[i] * sum_temp
  sum_temp -= int_list[i+1]
    
print(sum_num % (10 ** 9 + 7))

Submission status: Accepted

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

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

Submission status: Accepted

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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a)

ans %= 1000000007

print(int(ans))

Submission status: Accepted

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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a) % 1000000007

ans %= 1000000007
print(int(ans))

Submission status: Accepted

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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a) % mod

ans %= mod
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
b = []
for i in range(n):
  b.append(a[i])
i = n-2
while i >= 0:
  b[i] += b[i+1]
  b[i] %= mod
  i -= 1
#print(a)
#print(b)
ans = 0
for i in range(n-1):
  ans += a[i]*b[i+1]%mod
  ans %= mod
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    readline = sys.stdin.readline

    mod = 10**9 + 7

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

    sumA = sum(A) % mod
    ans = 0

    for i in A:
        sumA -= i
        ans += i * sumA
        ans %= mod

    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum_ans = sum(Ai)
ans = 0
mod = 1000000007

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

print(ans)

Submission status: Accepted

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

s = sum(a)
aa = [a[i]*a[i] for i in range(n)]
s2 = sum(aa)

print((s**2 - s2) //2%(10**9+7))

Submission status: Accepted

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

ans = 0
mod = int(1e9 + 7)
s = sum(A) % mod

for a in A:
    s -= a
    ans += (a * s) % mod
    ans %= mod

print(int(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
mod=10**9+7

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
b=[0]
for i in range(n):
  b.append(b[i]+a[i])
c=0
for j in range(n-1):
  c+=a[j]*(b[n]-b[j+1])
  while c//(10**9+7)>0:
    c%=10**9+7
print(c)

Submission status: Accepted

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

modS = [0]
for i in A:
    modS.append((modS[-1] + i) % MOD)

ans = 0
for i in range(1, N + 1):
    count = modS[-1] - modS[i]
    if count < 0:
        count = MOD + count
    ans = (ans + (A[i - 1] * count % MOD)) % 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
sumA = (sum(a) ** 2) % mod
ans = sumA
tmp = 0
for i in range(n):
    tmp += a[i] ** 2
    tmp %= mod
ans = (ans - tmp) % mod
print((pow(2, mod - 2, mod) * ans) % mod)
# print(ans // 2)

Submission status: Accepted

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

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)

Submission status: Accepted

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

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

ans = ans%m

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N=II()
A=LI()
#A.sort()
SA=sum(A)
#print(SA)
AccA=[A[0]]
for i in range(1,N):
  AccA.append(AccA[-1]+A[i])
  
#AccA.reverse()
ans=0
for i in range(N-1):
  ans+=A[i]*(SA-AccA[i])
  ans=ans%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
times = int(input())
numbers = list(map(int, input().split()))
result = 0
sum_numbers = sum(numbers)
calc = []

for i in range(times - 1):
  sum_numbers -= numbers[i]
  calc.append(sum_numbers)

for i in range(times - 1):
  calc[i] *= numbers[i]
  
print(sum(calc) % (10 ** 9 + 7))

Submission status: Accepted

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

mod = 10 ** 9 +7
amount = sum(A)
calc = []
for i in range(N - 1):
  amount = amount - A[i]
  calc.append(amount)

for i in range(N - 1):
  calc[i] *= A[i]

print(sum(calc) % mod)

Submission status: Accepted

Solution code:
 
N = int(input())

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

B = []

B_val = 0

ans = 0

for i in A[::-1]:
    B.append(B_val)
    B_val += i

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

print(ans % (1000000000 + 7 ) )

Submission status: Accepted

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

MOD = 10 ** 9 + 7

ans = 0
s = sum(A)
for a in A:
    s -= a
    ans += s * a
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

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

sums = [A_list[0]]

for i in range(1, N):
    sums.append(sums[i-1] + A_list[i])

result = 0
for i in range(1, N):
    result += sums[i-1] * A_list[i]

result %= 10**9 + 7

print(result)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
BIG = 10**9 + 7

def sumpp(n,a):
    acc = 0
    tmp = 0
    sumv = sum(a)
    for i in range(n):
        tmp += a[i]
        acc += a[i] * (sumv - tmp)
    return acc % BIG

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(sumpp(n,a))

Submission status: Accepted

Solution code:
import numpy as np

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

mod = 1000000007
res = np.cumsum(A, dtype=np.float64)
ans = 0

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

print(int(ans))

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    square = []
    for i in A:
        square.append(i**2)
    return (sum(A)**2 - sum(square))//2 % (10**9+7)


print(solve())

Submission status: Accepted

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

print(p)

Submission status: Accepted

Solution code:
mod = 10**9+7 

def main():
  n = int(input())
  a = list(map(int, input().split()))
  wa = sum(a)%mod
  ans = 0
  for i in range(n):
    wa -= a[i]%mod
    ans += (a[i]*wa)
    ans %= mod
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
sum_sum = sum(a[1:])
for i in range(N):

  sum_n = (sum_n + (a[i] * sum_sum) % MOD) % MOD
  if i+1 < N:
  	sum_sum = sum_sum - a[i+1]
print(sum_n % MOD)

Submission status: Accepted

Solution code:
N = map(int, input())
An = list(map(int, input().split()))
mnum = 10 ** 9 + 7
CumSum = An[0]
answer = 0
for i in range(1, len(An)):
    answer = (answer + CumSum * An[i]) 
    CumSum = (CumSum + An[i])
print(answer%mnum)

Submission status: Accepted

Solution code:
N = map(int, input())
An = list(map(int, input().split()))
mnum = 10 ** 9 + 7
CumSum = An[0] % mnum
answer = 0
for i in range(1, len(An)):
    answer = (answer + CumSum * An[i]) % mnum
    CumSum = (CumSum + An[i]) % mnum
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

Dum = 0
Gum = 0

for i in range(0, N-1):
    Dum += A[i]
    Gum += Dum * A[i+1]

print(Gum % 1000000007)

Submission status: Accepted

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

for i in num:
  s -= i
  ans += i*s
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()
mod = 10**9+7
s = sum(A)
s %= mod

a = s**2-sum(A[i]**2 for i in range(N))
a %= mod
a *= pow(2,mod-2,mod)
a %= mod

print(a)

Submission status: Accepted

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

sum_A = sum(A)

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i, a in enumerate(As, 1):
    ans += a*(SUM-a)
    ans %= mod
print(ans*pow(2, mod-2, mod)%mod)

Submission status: Accepted

Solution code:
import sys

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
su = sum(a)
res = 0
for x in a:
    res += su*x
    res -= x*x
print(res//2%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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