Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

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

Constraints

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

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
1 2 3

Sample Output 1

11

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

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     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

sum_A = sum(A)

tot = 0
for i in range(N):
    sum_A -= A[i]
    tot += A[i] * sum_A
        
print(tot % 1000000007)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
List = list(map(int, input().split()))
midList = [0]*(N-1)
mid = 0
for i in range(N-2,-1,-1):
  mid += List[i+1]
  midList[i] = mid
res=0
for i in range(N-1):
  a = List[i] % 1000000007
  b =  midList[i] % 1000000007
  res += a*b
print(res%1000000007)

Submission status: Accepted

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

sumA = sum(A)

ans = 0
for a in A:
  sumA -= a
  ans += sumA * a

print(ans % 1000000007)

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(v) for v in input().split()]
MOD = int(1e9 + 7)

S = sum(A)
SQ = S * S
IS = sum(a*a for a in A)

print(((SQ - IS) // 2) % 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 %(int(1e9 + 7))

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

n=int(input()) #3
alst=list(map(int,input().split())) #[1,2,3]

s=[0]
for i in range(len(alst)):
  s.append(s[i]+alst[i])

sum=0

for i in range(len(alst)-1):
  sum+=alst[i]*(s[len(s)-1]-s[i+1])

print(sum%MOD)

Submission status: Accepted

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

max = (10 ** 9) + 7

#入力配列の総和
line = 0
for i in range (n):
    line += a[i]

#a11, a22, ...対角線要素の総和
rem = 0
for i in range(n):
    rem += a[i]*a[i]

sum = ((line*line) - rem) // 2

ans = sum % max

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
S = sum(A)
S2 = sum(map(lambda x: x*x,A))
ans = (S*S - S2)// 2 % mod
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
import itertools
n = int(input())
a = list(map(int, input().split()))
cum = [0] + list(itertools.accumulate(a))
# print(cum)
ans = 0
mod = 10**9 + 7

for i in range(n):
    ans += a[i] * cum[i]
    # print(a[i], cum[i])

print(ans % mod)

Submission status: Accepted

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

mod = 1000000007


ans = 0
n = A[0]
for a in A[1:]:
    ans += a * n
    n += a

print(ans%mod)

Submission status: Accepted

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

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))
ans = ((S*S - S2)//2)%1000000007
print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from decimal import *
import random

n = int(input())
arr = list(map(int, input().split()))
cnt = 0
pref  = [0 for i in range(n)]
for i in range(n):
    cnt+=arr[i]
    pref[i] = cnt
ans = 0
for i in range(n):
    ans= (ans+(pref[n-1]-pref[i])*arr[i])%(int(1e9)+7)
print(ans)

Submission status: Accepted

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

c = 10**9+7


def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


inv = modinv(2, c)

sum_of_a = sum(A_list) % c
sum_of_sq_a = sum([i**2 for i in A_list]) % c

ans = (sum_of_a**2 % c - sum_of_sq_a)*inv %c

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
for i in range(n):
    ans+=l[i]*(tot-l[i])

print((ans//2)%mod)

Submission status: Accepted

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

for a in array:
    array_2.append(array_2[-1]+a)
    
output = 0
for i in range(len(array)-1):
    output += array[i] * (array_2[-1] - array_2[i+1])
    
print(output%mod)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(v) for v in input().split()]
mod = 1000000007
cusum = [0]
for i in range(N):
    cusum.append(cusum[i] + A[i])

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

Submission status: Accepted

Solution code:
import itertools

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

mod = 10**9+7

sum_ = 0
ans = 0

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

print(ans)

Submission status: Accepted

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

mod = 10**9 + 7

cusum = [0]
for i in range(n):
    cusum.append(cusum[i]+A[i])

totalSum = 0
for i in range(n-1):
    sum = (cusum[n] - cusum[i + 1]) % mod
    totalSum += sum * A[i]
    totalSum %= mod

print(totalSum)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()

sss = list(itertools.accumulate(A))
ss = sum(A)
s = 0
for i in range(len(A)-1):
    s = (s + ((ss-sss[i]) * A[i])) % mod

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


N = int(input())
A = list((input().split(" ")))

values = []
for i in range(N):
    values.append(int(A[i]))


suffixSumArray = values.copy()



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



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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data)

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
xs = Is()
mod = 1000000007

acc = xs[0]
ans = 0
for x in xs[1:]:
    ans += acc * x
    ans %= mod
    acc += x

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

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

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print(int((tmp*tmp-tmp2)//2)%1000000007)

Submission status: Accepted

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

mod = 1000000007

s= sum(a)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = pow(10, 9)+7
n = int(input())
lt = [int(x) for x in input().split()]

s = sum(lt)
ans = 0
for a in lt:
  s = s - a
  ans+= (a*s)%mod 
print(ans%mod)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
#Ai*Ajの和を求めろ
s=sum(A)
ans=0
for i in range(N-1):
    s=s-A[i]
    ans+=A[i]*s
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

result = 0

s = sum(n_list)
m = 10**9+7

for num in n_list:
    s -= num
    result += num * s % m
    result %= m

print(result)

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

S = [0]*(n+1)
ans = 0

for i in range(n):
    S[i+1] = S[i] + A[i]

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = tuple(map(int,input().split()))
mod = 10**9+7
B = [0]*N
for i in range(N):
    B[i] = A[i]**2
s1, s2 = 0, 0 
for i in range(N):
    s1 += A[i]
    s2 += B[i]
s1 = s1**2
ans = (s1 -s2)//2%mod
print(ans)

Submission status: Accepted

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

#for i in range(n-1):
#    for j in range(i+1,n):
#        ans += a[i]*a[j]
ans = 0
sum_a = 0
for i in range(n):
    ans += a[i]**2
    sum_a += a[i]
tmp = (sum_a ** 2 - ans)//2
print(tmp%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
for i in range(len(A)):
  A[i] = int(A[i])
C = 1000000007
mod = 0

#1
sum_A = sum(A)

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

print(mod)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

def func(N,A):
  result = 0
  S = sum(A) % MOD
  for x in A:
    S -= x
    S %= MOD
    result += x * S
    result %= MOD
  result %= MOD
  return result

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

Submission status: Accepted

Solution code:
n = input()
a_list = list(map(int, input().split()))
ruisekiwa = [0] * (len(a_list) + 1) 
for i in range(len(a_list)):
    ruisekiwa[i + 1] = ruisekiwa[i] + a_list[i]
sum_ = 0
mod = 10 ** 9 + 7
for i in range(len(a_list)):
    sum_ += ((a_list[i] % mod) * ((ruisekiwa[-1] % mod) - (ruisekiwa[i + 1] % mod))) % mod
print(sum_ % mod)

Submission status: Accepted

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

s = sum(a)
b = 10**9+7
ans = 0
for i in a:
  s -= i
  ans += i*(s%b)
  ans %= b
print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

res = 0
for v in A:
	res = (res + v * (s-v)) % MOD

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S = sum(A)**2 - sum(map(lambda x:x**2, A))

print(S//2 % 1000000007)

Submission status: Accepted

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

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

s = 0
summation = 0
for i in a_list:
  s += i

for i in a_list:
  s -= i
  summation += i * (s)

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
def main():
    n=int(input())
    a=list(map(int,input().split()))
    aa=list(accumulate(a))
    mod=10**9+7
    ans=0
    for i in range(n):
        ans += a[i]*(aa[-1]-aa[i])%mod
    print(ans%mod)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    MOD = int(1e09 + 7)
    S = sum(A)
    S -= MOD
    ans = 0
    for i in range(N):
        S -= A[i]
        ans += A[i] * S
        ans %= MOD
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 累積和を使う
for i in range(1,N+1):
    B[i] = A[i-1]+B[i-1]
# 累積和の配列完成
# print(B) 

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

Submission status: Accepted

Solution code:
mod = int(1e9 + 7)
n = int(input())
a = input().split()
sum = 0
for x in a:
    sum += int(x)
sum %= mod
ans = 0
for x in a:
    sum -= int(x)
    ans += int(x) * sum
    ans %= mod
print(ans)

Submission status: Accepted

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

sum = []

for i in range(N):
  if not sum:
    sum.append(A[i])
  else:
    sum.append(sum[i-1] + A[i])
    
product_sum = 0
    
for i in range(N-1):
  product_sum += A[i] * (sum[N-1] - sum[i])
  
print(product_sum % (10**9 + 7))

Submission status: Accepted

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

MOD =  10**9 + 7

ans = 0

t = sum(A)

for a in A:
    t -= a
    
    ans = ans + a * t
    ans %= MOD
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
target = 10 ** 9 + 7

N = int(input())

# 全ての整数のリスト作成
int_list = list(input().split())
int_list = [int(n) for n in int_list]

int_sum = sum(int_list)

sum_result = 0
for num in int_list:
    int_sum -= num
    sum_result += num * int_sum
print(sum_result % target)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
a_list = list(map(int, input().split()))
a_accumulate = list(itertools.accumulate(a_list))
a_sum = sum(a_list)
result = 0
i = 0
for a in a_list:
  result += a * (a_sum - a_accumulate[i])
  i += 1
print(result%(pow(10,9)+7))

Submission status: Accepted

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

mod= 10**9+7

A = sum(a)

ans=0

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A2 = list(map(lambda x: x ** 2, A))

sumA = sum(A)
sumA2 = sum(A2)

ans = (((sumA ** 2) - sumA2) // 2) % 1000000007

print(ans)

Submission status: Accepted

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

for x in a:
    S -= x
    S %= mod
    ans += S * x
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
def findProductSum(A, n):
    tmp = (10**9)+7

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

    array_sum_square = array_sum * array_sum

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

    return ((array_sum_square - individual_square_sum) // 2) % tmp

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

print(findProductSum(a,n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

A_sum = sum(A)

r = 0
for i, a in enumerate(A):
    x = A[i]*(A_sum - a)
    r = (r+x) % MOD

# print(r)

r = (r * pow(2, MOD-2, MOD)) % MOD

print(r)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
cum_sum = [0]
ans,sum = 0,0

# 累積和を求める
for i in range(len(A)):
    cum_sum.append(cum_sum[i]+A[i])

for i in range(n):
    # A[i+1]+A[i+2]+...+A[n]を累積和で求める
    sum = (cum_sum[n]-cum_sum[i+1])%1000000007
    # A[i]*(A[i+1]+A[i+2]+...+A[n])の処理
    # なおA[i+1]=A[j],A[i+2]=A[j+2]...である
    ans += A[i]*sum
    # 1000000007で割る
    ans %= 1000000007   
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-1):
    a = A[i]
    S -= a
    ans += a * S % MOD

print(ans % MOD)

Submission status: Accepted

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

print(res % mod)

Submission status: Accepted

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

for i in range(n-1):
    tmp += arr[i]%1000000007
    ans += tmp*arr[i+1] % 1000000007

print(ans%1000000007)

Submission status: Accepted

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

ans = 0
double = 0

for i in a:
    double += i*i

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
p = 1000000007
 
z = 0
for i in range(n):
    z += a[i]
    z = z % (2 * p)
z = (z ** 2) % (2 * p)
 
x = 0
for j in range(n):
    x += a[j] ** 2
    x = x % (2 * p)
 
w = int(((z - x) / 2) % p)
print(w)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = 0
ass = 0
ans = 0

for i in range(k):
    l += int(num[i])

for i in range(k):
    l -= int(num[i])
    ass += int(num[i]) * l
    

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

sum = 0
for x in a:
    sum += x
    sum %= MOD

ans = 0
for i in range(n):
    sum -= a[i]
    if sum < 0:
        sum += MOD
    ans += a[i] * sum
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
from itertools import accumulate

MOD = 10**9 + 7

N = int(input())
A = [0] + list(map(int, input().split()))
C = list(accumulate(A))

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

ans %= MOD
print(ans)

Submission status: Accepted

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

N = int(input())
A = [0] + list(map(int, input().split()))

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

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

ans %= MOD
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
n=int(input())
a=list(map(int, input().split()))
ans=0
anss=[0]*(n+1)
for i in range(1,n+1):
    anss[-i-1]=anss[-i]+a[-i]
    if anss[-i-1]>10**9+7:
        anss[-i-1]%=10**9+7
#print(anss)
for i in range(n-1):
    ans+=a[i]*anss[i+1]
    if ans>10**9+7:
        ans%=10**9+7
print(ans)