Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

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

Constraints

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

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
1 2 3

Sample Output 1

11

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

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
MOD = 10 ** 9 + 7


class ModInt:
    def __init__(self, x):
        if type(x) is str:
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(self.x * pow(other.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x)
            if isinstance(other, ModInt)
            else ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(other.x * pow(self.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(other, self.x, MOD))
        )


def main():
    n = int(input())
    ls = list(map(ModInt, input().split()))

    ans = ModInt(0)

    sm = sum(ls)

    for i in range(n):
        ans += ls[i] * sm

    sub = ModInt(0)
    for i in range(n):
        sub += ls[i] * ls[i]

    ans -= sub

    ans = ans / 2

    print(ans)


main()

Submission status: Accepted

Solution code:
#cやり直し
import numpy
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 +7

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template

mod = 10**9 + 7
N = int(input())
A = inputlist()

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

Submission status: Accepted

Solution code:
def solve(string):
    _, *a = map(int, string.split())
    return str((sum(a)**2 - sum(map(lambda x: x**2, a))) // 2 % (10**9 + 7))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
from itertools import accumulate


def solve(string):
    _, *a = map(int, string.split())
    ac = list(accumulate(a))
    ans = 0
    for _a, _c in zip(a, ac):
        ans = (ans + _a * (ac[-1] - _c)) % (10**9 + 7)
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
import numpy as np

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

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


ans = 0
mod = 10**9 + 7
s = 0

for i in range(N):
    s += A[i]
    s = s%mod

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

print(ans%mod)

Submission status: Accepted

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

tot = 0
num2 = [0]*(N-1)
numtot = sum(num)

for i in range(len(num)-1):
  numtot -= num[i]
  num2[i] = numtot % (10**9+7)
  
  num1 = num[i] % (10**9+7)
  
  tot += num1 * num2[i]
  
  if tot >= (10**9+7): tot = tot % (10**9+7)

print(tot)

Submission status: Accepted

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

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

Submission status: Accepted

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

d = 10**9 + 7
s = sum(A)
ans = 0
for i in range(len(A) - 1):
    s = s - A[i]
    ans += A[i] * (s)

print(ans % d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

MOD = 10**9 + 7

n = int(input())

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

x = pow(sum(a), 2)
y = sum((a[i]**2 for i in range(n)))

sum = (x - y) // 2 % MOD

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
array = list(map(int,input().split()))
num_sum = 0
tmp_sum = 0

tmp_sum = sum(array)

for a in array:
      tmp_sum -= a
      num_sum += tmp_sum*a

print(num_sum % 1000000007)

Submission status: Accepted

Solution code:
from itertools import accumulate


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

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

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')
mod = 10**9 + 7

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())


n = I()
a = RI()

s = sum(a)

ls = []
for i in range(n):
    s -= a[i]
    ls.append(s)
# print(ls)

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

Submission status: Accepted

Solution code:
n = int(input())

s = input().split(" ")

sumup = 0
for i in s:
  sumup += int(i) 

ans = 0
for i in s:
  r = int(i)
  
  sumup -= r
  
  ans += r*sumup
    
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())

s = input().split(" ")

sumup = 0
for i in s:
  sumup += int(i) 

ans = 0
for i in s:
  r = int(i)
  
  sumup -= r
  
  ans += r*sumup
    
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
B = [0]
a = len(A)
sa = sorted(A)
su = 0
p = 10**9+7

for i in range(a):
    B.append(B[i] + sa[i])

for j in range(a):
    su += sa[j]*B[j]

print(su%p)

Submission status: Accepted

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

Submission status: Accepted

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

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()))
a1 = sum(A)%p
B = [A[i]**2 for i in range(N)]
a2 = 0
for i in range(N):
    a2 = (a2+B[i])%p
ans = (((a1*a1)%p-a2)%p * pow(2,p-2))%p
print(ans)

Submission status: Accepted

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

ans = sum(al)**2
for a in al:
    ans -= a**2

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from numba import njit, i8
import sys
read = sys.stdin.readline
mod = 10 ** 9 + 7


@njit((i8, i8[:]), cache=True)
def main(n, a):
    s = np.zeros(n + 1, dtype=np.int64)
    for i in range(n):
        s[i + 1] = (a[i] + s[i]) % mod
    ans = 0
    for i in range(1, n):
        ans = (ans + a[i] * s[i] % mod) % mod
    print(ans)


n = int(read())
a = np.fromstring(read(), dtype=np.int64, sep=' ')
main(n, a)

Submission status: Accepted

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

S = 0
ans = 0
for a in A:
    ans = (ans + a * S) % MOD
    S += a
print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
N = int(input())
array = list(map(int,input().split()))
num_sum = 0
tmp_sum = 0

tmp_sum = sum(array)

for a in array:
    tmp_sum -= a
    num_sum += tmp_sum*a

print(num_sum%1000000007)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

li = list(map(int,input().split()))
li_1 = []
mod = 10**9+7

a = 0
for i in range(1,len(li)):
    total = li[i] * (a +li[i-1])
    a += li[i-1]
    li_1.append(total)

print(sum(li_1)%mod)

Submission status: Accepted

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

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

Submission status: Accepted

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

result= 0
asum = sum(a)
for j in range(0,n):
  asum -= a[j]
  result += a[j]*(asum)

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=[int(i) for i in sys.stdin.readline().split()]
temps=[a[0]]+[0]*n

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

print(ans)

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
aa = list(accumulate(a))
MOD = 10**9+7
ans = 0
for i in range(n):
    ans += a[i]*(aa[n-1] - aa[i])
print(ans%MOD)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
aa = list(accumulate(a))
MOD = 10**9+7
ans = 0
for i in range(n):
    ans += a[i]*(aa[n-1] - aa[i]) % MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split()))
mod = 1000000007
c_sum = [0] * n
c_sum[n - 1] = aaa[n - 1]
ans = 0

for i in range(n - 2, 0, -1):
    c_sum[i] = (c_sum[i + 1] + aaa[i]) % mod

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
mod = 1000000007

a = sum(A)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
num_list =  [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
    #A*B + A * C = A*(B+C)で計算
    right -= number
    result += (number * right) % mod
print(result % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int(),stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
n=int(I())
a=LI()
sum=0
for i in range(len(a)):
    sum+=a[i]
norm=0
for i in range(len(a)):
    norm+=a[i]**2
print(((sum**2-norm)//2)%(10**9+7))

Submission status: Accepted

Solution code:
MOD=1000000007
N=int(input())
A=list(map(int,input().split()))
x=sum(A)%MOD
ans=x*x%MOD
ans+=sum(MOD-A[i]*A[i]%MOD for i in range(N))
ans%=MOD
ans*=500000004
ans%=MOD
print(ans)

Submission status: Accepted

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

sq_sum = sum(map(lambda x: x*x, A))
sum_sq = sum(A) * sum(A)
answer = (sum_sq - sq_sum) // 2

print(answer % mod)

Submission status: Accepted

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

mod = 10 ** 9 + 7
sums = sum(arr)

answer = 0
for num in arr:
    sums -= num
    answer = (answer + (sums * num)) % mod

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

S = sum(A)**2

T = 0
for a in A:
    T+=a**2

S -= T
S //= 2
S%=mod
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(score%mod)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

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

ans = 0
S = sum(A)
for i in A:
    S -= i
    ans += i * S
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
#abcdef
#a*b,a*c,a*d,a*e,a*f
#b*c,b*d,b*e,b*f
#c*d,c*e,c*f
#d*e,d*f
#e*f

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

mod = 10**9 + 7
all_l = 0
for i in range(n):
    all_l += l[i]
    all_l %= mod

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ary = [0]*(N-1)
for i in reversed(range(N-1)):
    if i+1 >= (N-1):
        ary[i] = A[N-1]
    else:
        ary[i] = ary[i+1] + A[i+1]

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

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

Submission status: Accepted

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

def calculate(n, arr):
    mod = 1000000000 + 7
    result = 0

    rightTotal = sum(arr)
    for i in range(n-1):
        rightTotal -= arr[i]
        result += (arr[i] * rightTotal) % mod

    print(result % mod)




calculate(N, ARR)

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
L=list(map(int,input().split()))
s=0
t=0
p=10**9+7
x=5*10**8+4
for i in range(0,n):
	s=(s+L[i])%p
	t=(t+L[i]*L[i])%p

ans=x*(pow(s,2,p)-t)

print(ans%p)

Submission status: Accepted

Solution code:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    sum = 0
    for i in range(0, n):
        sum += aList[i]

    pro = 0
    for i in range(0, n):
        ai = aList[i]
        sum = sum - ai
        pro += sum * aList[i]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    A_cum_sum = [A[-1]]
    for a in A[::-1][1:]:
        A_cum_sum.append(a + A_cum_sum[-1])
    A_cum_sum = A_cum_sum[::-1]
    ans = 0
    for i in range(N-1):
        sum_mod = A_cum_sum[i+1] % mod
        mul_mod = (A[i] * sum_mod) % mod
        ans = (ans + mul_mod) % mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
acc = [0]*(n+1)
for i in range(n-1,-1,-1):
    acc[i] = acc[i+1]+a[i]
#ddprint(acc)
x = 0
for i in range(n-1):
    #ddprint(f"{x=} {i=} {acc[i+1]}")
    x = (x+a[i]*acc[i+1])%R
print(x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8
a = int(input())
b = list(map(int,input().split()))
s = 0
for i in range(a):
    s +=b[i]
tr = 0
for i in range(a):
    tr += b[i]**2
a2 = s**2-tr
a = a2//2
a %= 10**9+7
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)

Submission status: Accepted

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

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

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

a2 = s ** 2 - tr
a = a2 // 2
a %= 10 ** 9 + 7

print(a)

Submission status: Accepted

Solution code:
import numpy as np

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

modn = int(1e9 + 7)

ruiseki = sum(A)

ret = 0
for i in range(0, len(A)-1):
  ruiseki -= A[i]
  ret += A[i] * ruiseki

print(np.mod(ret, modn))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C問題

#計算量の意識(O(N^2)では間に合わない)
#合同式-あまりの計算の性質
#a≡b ならば、a + c ≡　b + c, a - c ≡　b - c , a * c ≡　b * c 　つまり和差積については途中であまりを取って計算可能

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

S = sum(A) % MOD

ans = 0

#MODはいちいち取る癖をつける
for x in A:
    S -= x
    S %= MOD
    ans += S * x
    ans %= MOD
    
#MODは必要以上に取りすぎてもOK 忘れないためにもう一度
ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    # d,t,s = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    mod = 10**9+7

    s = sum(a)

    sm = 0

    for i in a:
        s -= i
        sm += i * s % mod

    print(sm % mod)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
n = ii()
alist = lmis()

asum = sum(alist[1:n])

sum = 0
for i in range(n-1):
    sum += alist[i] * asum
    asum -= alist[i+1]

print(sum % 1000000007)

Submission status: Accepted

Solution code:
KK=10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
X=0
K=sum(A) %KK
for x in A:
    K-= x 
    X+=K*x
    X%=KK

print(X)

Submission status: Accepted

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

# 累積和
s=[0]
K=0
for i in range(N):
    K+=A[i]
    s.append(K)
U=0
for i in range(N-1):
    U+=A[i]*(s[N]-s[i+1])
print(U%(10**9+7))

Submission status: Accepted

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

ruiseki=ruiseki[1:]
mod=10**9+7
ma=max(ruiseki)
ans=0
for i in range(len(a)):
  ans+=((ma-ruiseki[i])*a[i])%mod
print(ans%mod)

Submission status: Accepted

Solution code:
import sys,itertools,collections,bisect
from collections import deque,Counter,defaultdict
from heapq import heappush,heappop,heapify
read=sys.stdin.readline
sys.setrecursionlimit(10**6)

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

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7  # MODは変数に入れてしまったほうが打ち間違えなくていいです

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

S = sum(A) % MOD
ans = 0

# A_Nも含まれてしまいますが、そのときはs=0なので問題ありません
for x in A:
    S -= x  # 自分と自分自身を掛けないように、先に引く必要があります
    S %= MOD  # MODはいちいち取っておくといいです
    ans += S * x
    ans %= MOD

ans %= MOD  # この行は完全に不要ですが、最後だけMODを取り忘れてWAになるミスは非常によくあるので、必要以上に取っておくと安心できます
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# 日本語を入力できるようにするために上記一文が必要


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

j_sum = 0
for j in range(N):
        j_sum = j_sum + A_input[j]


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    S = [0]
    for i in range(n):
        S.append(S[i]+A[i])
    ans = 0
    for i in range(n-1):
        ans += (( A[i] * (S[-1] - S[i+1])) % MOD)
    print(ans%MOD)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().strip())
vs = [int(a) for a in sys.stdin.readline().strip().split(" ")]

M = 1000000000 + 7

ret = 0
sum = 0
for j in range(1, N):
    sum += vs[j - 1]
    ret += (vs[j] * sum) % M
    ret = ret % M
print(ret)

Submission status: Accepted

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

P = sum(A)**2
Q = 0
for i in range (0, N):
    Q+=(A[i])**2

print(((P-Q)//2)%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 1000000007
print(((sum(a)**2 - sum(map(lambda x: x**2, a))) // 2) % m)

Submission status: Accepted

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

mod = 10**9 + 7

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

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,*A = map(int, open(0).read().split())
s = 0
m = 1000000007
for x in A:
    s = (s+x) % m
ans = 0
for x in A:
    s = (s-x) % m
    ans = (ans+x*s) % m
print(ans)

Submission status: Accepted

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

S = sum(a)
S2 = 0

for i in a:
    S2 += i * i

print((S*S - S2)//2 % inf)

Submission status: Accepted

Solution code:
# coding: utf-8

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

    a_sum = sum(a_list)
    ans = 0 
    for i in range(n-1):
        a_head = a_list[i]
        a_sum -=  a_head
        ans += a_head * a_sum
    
    print(ans % (10**9 + 7))
        

main()