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:
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
A = list(map(int,input().split()))
a0 = ((sum(A)%p)*(sum(A)%p))%p
a1 = 0
for i in range(N):
    a1 = (a1+A[i]**2)%p
a = a0-a1
a = (pow(2,p-2)*a)%p
print(a)

Submission status: Accepted

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

mod=10**9+7

s=sum(a)%mod

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

print(ans)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    ans = sum(A)
    ans *= ans
    ans -= sum([a * a for a in A])
    ans //= 2
    ans %= 1000000007
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
s = sum(A)
mod = 10**9+7
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:
from itertools import accumulate


N = int(input())
A = list(map(int, input().split()))
MOD = 1_000_000_007
acc = list(accumulate(A, initial=0))

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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
total=sum(a)

mod=10**9+7

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input()); MOD = pow(10,9)+7
A = list(map(int,input().split()))
S = sum(A)**2%MOD
nijo = 0
for x in A:
  nijo = (nijo + x**2)%MOD
ans = (S-nijo)*pow(2,MOD-2,MOD)%MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)

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

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
ans = (sum(A)**2 - sum(a*a for a in A))//2
mod = 10**9 + 7

print(ans % mod)

Submission status: Accepted

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

length = len(a)
total = sum(a)

ans = 0
for i in range(0,length):
    total -= a[i]
    ans += (a[i] * total)


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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]


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

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

s2 =0
for i in range(N):
    s2 += seq[i]**2


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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
t=sum(a)
s=0
for i in range(n):
  s+=a[i]*a[i]

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



print(ans)

Submission status: Accepted

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

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

print(ans%MOD)

Submission status: Accepted

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

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

Submission status: Accepted

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

mod = 10**9 + 7
memo = {}

for i in range(n):
    if i == 0:
        memo[n-i-1] = 0
    else:
        memo[n-i-1] = (memo[n-i] + arr_a[n-i]) % mod

ans = 0
for i in range(n):
    ans += arr_a[i] * memo[i]
    ans = ans % mod

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
num_list = input().split()

mod_value = 10**9 + 7
sum_all = 0
sum_int = 0

for index in range(len(num_list) - 1):
  sum_int += int(num_list[index])
  sum_all += sum_int * int(num_list[index + 1])
  if sum_all > mod_value:
    sum_all %= mod_value

print(sum_all)

Submission status: Accepted

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

Submission status: Accepted

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7

res = 0
total = sum(arr)

# print(total)
# print(arr)
for a in arr:
    total -= a
    res += total * a % MOD
    # print(res)


print(res % MOD)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sum_l=sum(l)
ans=0
mod=10**9+7

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

Submission status: Accepted

Solution code:
N=int(input())
B=[int(a) for a in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

total=0

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

Submission status: Accepted

Solution code:
MOD = 1000000007
n = int(input())
nums = list(map(int, input().split()))
x = sum(nums)
y = sum([(nums[i]**2) for i in range(n)])
print(((x**2 - y)//2)% MOD)

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
 

def cumsum(xs):
    pass

def main():
    n = int(input())
    alist = list(map(int, input().split()))
    max_num = 10**9 + 7
    ans = 0
    sum_num = sum(alist)

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

    print(ans%max_num)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())

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

mod=10**9+7
summy=[]
a=0
for i in range(N):
    a += A[i]
    a %= mod
    summy.append(a)

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

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

S = sum(A) % MOD
ans = 0

for i in A:
    S -= i
    ans += S*i
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li_a = list(map(int, input().split()))
answer = 0
su = sum(li_a)
mo = (10 ** 9) + 7
for idx, a in enumerate(li_a):
    su = su - a
    answer += (a * su)
print(answer % mo)

Submission status: Accepted

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

mod = 10**9 + 7
ans = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

S = sum(A) % MOD
ans = 0

for x in A:
  S -= x
  S % MOD
  ans += S * x
  ans %= MOD
  
print(ans)

Submission status: Accepted

Solution code:
#整数値入力 1文字の入力
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()))

n = input_one_number()
a = input_multiple_number_as_list()

mod = 10**9+7
ssum = 0

sumA = sum(a)

for _a in a:
	ssum += _a * (sumA-_a)

print(ssum//2%mod)

Submission status: Accepted

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

sum = [0]
sum1 = 0
for i in range(N):
    sum.append(num[i] + sum[i])

for x in range(N):
    if((num[x] * sum[x])//(10**9 + 7)>= 1 ):
        sum1 += num[x]*sum[x] - ((num[x] * sum[x])//(10**9 + 7))*(10**9 + 7)
    else:
        sum1 += num[x]*sum[x]

print(sum1 - (sum1//(10**9 + 7))*(10**9 + 7) )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())
a_list = list(map(int, input().split()))
a_list = np.array(a_list)

a = a_list.sum() % MOD
b = ( (a_list**2)%MOD ).sum() % MOD
c = ( a**2 - b) % MOD

if c&1:
    c += MOD

print(c//2)

Submission status: Accepted

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

s_2 = 0
for i in a_list:
    s_2 += i**2

ans = (sum(a_list)**2 - s_2)//2  

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

Submission status: Accepted

Solution code:
N = int(input())
Al = input().split()
A = list( map((lambda x: int(x)), Al))
num = 0
ma = 10**9 + 7
li = 0

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

num = num % ma
print(num)

Submission status: Accepted

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

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):
  sum_A = (sum_A - A[i])%(10**9 + 7)
  ans += A[i] * sum_A
  
print(ans%(10**9 + 7))

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):
  sum_A = sum_A - A[i]
  
  ans += A[i] * sum_A
  
print(ans%(10**9 + 7))

Submission status: Accepted

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

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

print(ans%mod)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

_INPUT = """\
4
141421356 17320508 22360679 244949
"""

def main(*, input=input):
    sr = lambda: input()
    ir = lambda: int(sr())
    lr = lambda: list(map(int, sr().split()))

    n = ir()
    a = lr()
    a1 = [0]
    for num in a:
        a1.append(a1[-1]+num)
    ans = 0
    for i,num in enumerate(a):
        tmp = (a1[n]-a1[i+1])%mod
        tmp = (tmp*num)%mod
        ans = (ans+tmp)%mod
    print(ans)

if __name__ == "__main__":
    import io, sys

    # sys.stdin = io.StringIO(_INPUT)

    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
MOD= 10**9 + 7
toki = [0]*(n+1)
shigi=0

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

print(shigi%MOD)

Submission status: Accepted

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

Submission status: Accepted

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

# 累積和(Cumulative sum)リストの作成
cumsum = [0]*(n+1)
for i in range(n):
    cumsum[i+1] = lst[i] + cumsum[i]

# 題意より、lst の1つ前までが対象
ans = 0
for i in range(n-1):
    ans += (cumsum[n] - cumsum[i+1]) * lst[i]
print(ans % mod)

Submission status: Accepted

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

# 累積和リストの作成
sums = [0]*(n+1)
for i in range(n):
    sums[i+1] = lst[i] + sums[i]

# 題意より、lst の1つ前までが対象
ans = 0
for i in range(n-1):
    ans += (sums[n] - sums[i+1]) * lst[i]
print(ans % mod)

Submission status: Accepted

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

print(ans % mod)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
cum_A = [0] * N
cum_A[0] = A[0]
for i in range(1, N):
    cum_A[i] = cum_A[i - 1] + A[i]

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

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

Submission status: Accepted

Solution code:
##C - Sum of product of pairs
##累積和
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
ans = 0
for i in range(N-1):
    ans += A[i]*(S - A[i])
    S -= A[i]
print(ans % (10**9+7))

Submission status: Accepted

Solution code:
import itertools
#h,w=map(int,input().split())
#S=[list(map(int,input().split())) for _ in range(h)]
n=int(input())
A=list(map(int,input().split()))
Ar=list(itertools.accumulate(A))
ans=0
for i in range(n-1):
    ans+=A[i]*(Ar[n-1]-Ar[i])
    ans%=10**9+7
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = map(int, input().split())
S = 0
S2 = 0
M = 10**9+7
for a in A:
  S += a
  S %= M
  S2 += a*a
  S2 %= M

# (S * S - S2)/2 
ans = (S * S - S2) * pow(2, -1, M)
ans %= M
print(ans)

Submission status: Accepted

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

mod = 10 ** 9 + 7
sum = sum(A) **  2

squ = 0
for i in range(N):
    squ +=  A[i] ** 2

answer = int(((sum - squ)  //  2 ) % mod)
print(answer)

Submission status: Accepted

Solution code:

mod = 10 ** 9 + 7


N = int(input().rstrip())
As = list(map(int, input().rstrip().split()))
ans = 0
add = 0

for i in range(N):
	add += As[i]
	add %= mod
ans = add * add % mod

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

ans *= int((mod + 1) / 2)
ans %= mod

print(ans)

Submission status: Accepted

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

A_sum = sum(A)
A_squaresum = sum([a ** 2 for a in A])
answer = ((A_sum ** 2 - A_squaresum) // 2) % (10 ** 9 + 7)

print(answer)

Submission status: Accepted

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

x = sum(A)
y = sum([A[i] ** 2 for i in range(N)])

print(((x ** 2 - y) // 2) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) // 2
    print(int(ans % mod))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# C - Sum of product of pairs
import numpy as np

N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
A = np.array(A)
csA = np.zeros((N+1), np.int64)
for i in range(N):
    csA[i+1] = (csA[i] + A[i]) % MOD
    
ans = 0
for i in range(N-1):
    ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD)

Submission status: Accepted

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

n = int(input())
a = readInt()
b = 0
ans = 0

for i in a:
    b += i ** 2

# print(sum(a))
ans = ((sum(a) ** 2 - b) // 2) % (10 ** 9 + 7)
print(ans)

Submission status: Accepted

Solution code:
# C - Sum of product of pairs

N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
S = sum(A)

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

Submission status: Accepted

Solution code:
# input here
_INPUT = """\
4
141421356 17320508 22360679 244949
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
def main():
    n = int(input())
    a = list(map(int, input().split()))
    cumsum = list(itertools.accumulate(a))

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

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


if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools
    from collections import deque

    # sys.stdin = io.StringIO(_INPUT)
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    accm = list(accumulate(A))

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

    print(ans%MOD)
        

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

mod=10**9+7

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

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

print(int(ans))

Submission status: Accepted

Solution code:
mod = 1000000007
n = int(input())
a = list(map(int, input().split()))
ans = 0
a_sum = sum(a) 
a_total = a_sum*a_sum
lat = 0
for i in a:
    lat = lat + i*i
ans = (a_total - lat) // 2
ans = ans%mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
for i in range(N):
    sum += As[i]
    sum %= 10**9+7

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

print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    ans = (sum(A) ** 2 - sum([i ** 2 for i in A])) // 2 % MOD
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

n_sum = a[0]
sum = 0
for i in range(1,n):
  sum += a[i] * n_sum
  n_sum += a[i]
print(sum % (10**9 + 7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

A.sort()
ac = list(itertools.accumulate(A))

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

Submission status: Accepted

Solution code:
def execute(N, A):
    dst = 0
    s = sum(A)
    for v in A:
        s -= v
        dst += v * s

    return dst % (10**9+7)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    print(execute(N, A))

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 0
sum = 0

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

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

m = 10**9 + 7

ans = ans % m

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    mod = 10**9 + 7
    sum_A = sum(A)%mod
    ans = 0
    for a in A:
        sum_A -= a
        ans += a*sum_A%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
p = 10**9 + 7
A = [int(i) for i in input().split()]
S = sum(A)%p
ans = S**2 % p
B = [(i**2%p) for i in A]
ans -= sum(B)%p
if ans < 0:
    ans += p
if ans % 2 == 0:
    print(ans//2)
else:
    print((ans+p)//2)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
S = [0] * (N+1)      #累積和用のリスト
s = 0
CONST = 10**9+7

#前準備として累積和を計算
for i in range(N):
    S[i+1] = S[i] + A[i]

#積の総和を計算
for i in range(N-1):
    s += A[i] * ((S[N] - S[i+1]) % CONST)
    s %= CONST

print(s)

Submission status: Accepted

Solution code:
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n=int(input())
A=input_array()
acc_A=[0]

for i in range(n):
	acc_A.append(acc_A[i]+A[i])
ans=0
for i in range(n):
	ans+=A[i]*(acc_A[n]-acc_A[i+1])

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

Submission status: Accepted

Solution code:
N = int(input())

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

MOD = 10 ** 9 + 7

x = 0
ans = 0
for i in range(len(A)):
    ans += A[i] * x % MOD
    x += A[i] % MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())

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

MOD = 10 ** 9 + 7

x = 0
ans = 0
for i in range(len(A)):
    ans += A[i] * x
    x += A[i]
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())

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

MOD = 10 ** 9 + 7

edge = sum(A)

diagonal_sum = 0
for num in A:
    diagonal_sum += num ** 2

s = (edge*edge - diagonal_sum) // 2

print(s % MOD)

Submission status: Accepted

Solution code:
m = 1000000007

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

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

Submission status: Accepted

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

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)

Submission status: Accepted

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

MOD = 10**9 + 7
s = 0
for i in a:s+=i

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

Submission status: Accepted

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

ans = (total - cnt) // 2
ans %= mod

print(ans)

Submission status: Accepted

Solution code:
m = 1000000007

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

result = 0
c = 0
for a in A:
    result += c * a
    result %= m
    c += a
    c %= m
print(result)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(j)for j in input().split()]
mod=10**9+7
ll=[i**2 for i in l]
ans=(sum(l)**2-sum(ll))//2
print(ans%mod)

Submission status: Accepted

Solution code:
N=int(input())
A=input().split()
A=[int(i) for i in A]
S=0
A_sum=0
for i in range(N):
    A_sum+=A[i]
    

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

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

Submission status: Accepted

Solution code:
def solve(N, As):
    Ss = [0]
    total = 0
    for a in As:
        Ss.append(Ss[-1] + a)
    for i in range(N - 1):
        total += As[i] * (Ss[-1] - Ss[i + 1])
    ans = total % (10 ** 9 + 7)
    print(ans)


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split()))
    solve(N, As)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
l = [a[0]]
for i in range(1, n):
  l.append(l[i-1]+a[i])

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

print(ans)