Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

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

Constraints

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

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
1 2 3

Sample Output 1

11

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

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)**2
    t = 0
    for a in A:
        t += a**2
    
    ans = (s - t) // 2
    print(ans % 1000000007)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = ((sum(A)*sum(A) - tmp)//2)%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = map(int,read().split())

MOD = 10**9+7
i2 = (MOD+1)//2


r = sum(a)
r *= r
r -= sum(i*i for i in a)

r *= i2
print(r%MOD)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

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

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

print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
s = 0
for i in range(N):
    a = A[i]
    s += a
    s %= MOD
t = s*s
for i in range(N):
    a = A[i]
    t -= a*a
    t %= MOD
t %= MOD
if t % 2 == 0:
    print(t // 2)
else:
    print((t+MOD)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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

  l=[0]
  for x in A:
    l.append(l[-1]+x)

  # print(l)

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

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
sm = sum(a) % mod
ans = 0
beki = 0

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N, *A = map(int, read().split())
    SUM = sum(A)
    ans = 0
    for a in A:
        ans += ((SUM - a) * a)%mod
        ans %= mod
        SUM -= a
    print(ans)


if __name__ == "__main__":
    run()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
N = input()
A = [int(hoge) for hoge in input().split()]
S = 0
Scube = 0
for a in A:
    S += a
    Scube += a**2
    S %= MOD
    Scube %= MOD
Double = S**2 - Scube
Double %= MOD
if Double%2:
    Double += MOD
    Double //= 2
else:
    Double //= 2
print(Double)

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=II()
	A=LI()

	m=10**9+7

	S=sum(A)
	S%=m
	ans=0


	for i in A:
		S-=i
		S%=m
		ans+=i*S
		ans%=m
	print(ans)









if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

n = INT()
a = LIST()
b = 0

ans = 0
for i in range(n-2, -1, -1):
    b += a[i+1]
    b %= (pow(10,9)+7) 
    ans += a[i]*b % (pow(10,9)+7)
    ans %= (pow(10,9)+7)

print(ans)

Submission status: Accepted

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

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

print(ans%mod)

Submission status: Accepted

Solution code:
MOD=10**9+7
N=int(input())
ls=[int(s)%MOD for s in input().split()]
s=0
d=0
for x in ls:
  s=(s+x)%MOD
  d=(d+x*x)%MOD

ans=((s*s-d)*500000004)%MOD
print(ans)

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))
z=(x*x-y)//2

print(z%1000000007)

Submission status: Accepted

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

mod = pow(10,9)+7

ruiseki = [0]
for a in A:
    ruiseki.append((ruiseki[-1]+a)%mod)

total = 0
for i in range(1,N+1):
    bubun_sum = (ruiseki[-1]-ruiseki[i])%mod
    bubun_total = (A[i-1]*bubun_sum)%mod
    total = (total+bubun_total)%mod

print(total)

Submission status: Accepted

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

for i in range(n-1):
	answer = (answer+a[i]*b[i+1])%MOD
print(answer)

Submission status: Accepted

Solution code:
MOD = 1000000007
n, *a = map(int, open(0).read().split())
wa = a + [0]
for i in range(n-1, 0, -1):
    wa[i-1] += wa[i]

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
n = ni()
A = lma()
mod=10**9+7
tot = 0
for a in A:
    tot = (tot+a)%mod
ans = 0
for a in A:
    tot =(tot-a)%mod
    ans+=(tot*a)%mod
print(ans%mod)

Submission status: Accepted

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

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

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

if ans % 2 == 0:
  print(ans // 2)
else:
  print((ans + MOD) //2)

Submission status: Accepted

Solution code:
MOD = 10**9+7

n = int(input())
a = list(map(int,input().split()))
asum = []
tmp = sum(a)
for i in a:
    tmp -= i
    asum.append(tmp)

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

Submission status: Accepted

Solution code:
import sys


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


MOD = 10**9 + 7


def main():
    n = _i()
    a = list(_ia())
    s = [0] * n
    for i in range(n-2, -1, -1):
        s[i] = s[i+1] + a[i+1]

    ans = 0
    for ai, si in zip(a, s):
        ans = (ans + (ai * si)) % MOD
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

NUM = 1000000007
inv2 = 500000004
assert (inv2 * 2) % NUM == 1

As2 = 0
A2s = 0

for a in A:
    As2 += a
    As2 %= NUM
    
    A2s += a ** 2
    A2s %= NUM

As2 = (As2 ** 2) % NUM

ans = (As2 + NUM - A2s) % NUM
ans *= inv2
ans %= NUM

print(ans)

Submission status: Accepted

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

a = sum(A)
a *= a

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
MOD = int(1e9+7)
k = (MOD + 1) // 2

ans = sum(a)**2 % MOD
for ai in a:
    ans -= ai**2
    ans %= MOD
ans *= k
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)
ans = 0
for i, a in enumerate(A):
    s -= a
    ans = (ans + s * a) % mod

print(ans)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
mod = 10 ** 9 + 7

s = [0] * n

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

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

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

Submission status: Accepted

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

Submission status: Accepted

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


S = [sum(A) % MOD]
for i in range(N):
    S.append(S[-1]-A[i])

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))
s = 0
ss = 0
for ai in a:
    s += ai
    ss += ai*ai
    s %=mod
    ss %=mod

x = pow(2,mod-2,mod)
ret = (s*s-ss)%mod
ret = ret*x
ret %=mod

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = list(accumulate(A))
MOD = 10**9 + 7
res = 0
for i in reversed(range(1,N)):
    res += S[i-1]*A[i]
    res %= MOD
print(res)

Submission status: Accepted

Solution code:
from itertools import accumulate

m = 1000000007

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

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

Submission status: Accepted

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

mod = 10**9 + 7

S = 0
T = 0

for i in range(len(A)):
    S += A[i]
    T += A[i]**2
    S %= mod
    T %= mod

print(((S**2-T)*pow(2,mod-2,mod))%mod)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

mod = 10**9+7

su = sum(A)

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

print((ans * 500000004)%mod)

Submission status: Accepted

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

acc = [0]
for a in A:
    acc.append((acc[-1]+a)%mod)

ans = 0
for i in range(n-1):
    ans += ((acc[-1]-acc[i+1])*A[i])% mod
    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
    ans %= 10**9+7
print(ans)

Submission status: Accepted

Solution code:
#[int(i) for i in input().split()]
P = 1000000007
n = int(input())
a = [int(i) for i in input().split()]
pref = [0]*n
pref[n-1] = a[n-1]
for i in range(n-2,-1,-1):
	pref[i] = pref[i+1]+a[i]

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

Submission status: Accepted

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

prefix = [0]
for a in A:
    prefix.append(prefix[-1] + a)

res = 0
M = 10 ** 9 + 7
for i, a in enumerate(A[:-1], start=1):
    res += a * (prefix[N] - prefix[i])
    res %= M
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A_sum = sum(A)
A2 = sum([i*i for i in A])
print(((A_sum * A_sum - A2)//2) % (10**9+7))

Submission status: Accepted

Solution code:
def mod(num):
    return num % (10 ** 9 + 7)


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

Asum = sum(A)

ans = 0

for i, a in enumerate(A):
    Asum -= a
    ans = mod(ans + Asum * a)

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    cumsum = [0]
    for i in range(N):
        cumsum.append(cumsum[i] + A[i])
    ans = 0
    for i in range(N):
        ans += (A[i] * ((cumsum[N] - cumsum[i+1]) % mod)) % mod
        ans %= mod
    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
A.reverse()
sumA=[0,]+list(accumulate(A))
mod=10**9+7
ans=0
for a, s in zip(A, sumA):
    ans+=((a%mod)*(s%mod))%mod
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
csum = [0] * n
now = 0
for i in range(n):
    now += a_ls[i]
    csum[i] = now

mod = 10**9+7
ans = 0
for i in range(n):
    add = a_ls[i] * ((csum[-1] - csum[i])%mod)
    add %= mod
    ans += add
    ans %= mod
print(ans%mod)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

for i in range(len(a)):
  am-=a[i]
  sm=(sm+a[i]*am)%(10**9+7)
print(sm)

Submission status: Accepted

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
from itertools import accumulate
AA = [0] + list(accumulate(A))
mod = 10**9+7

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

Submission status: Accepted

Solution code:
def inverse(a, mod):
    a %= mod # 除数が正なら正になる
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod # 除数が正なら正になる
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
s = sum(a)

ans = 0
for x in a:
    ans = (ans + x * (s - x)) % mod
print (ans * inverse(2, mod) % mod)

Submission status: Accepted

Solution code:
import math
from fractions import Fraction as frac

MOD = 1000000007

def solve(case_no):
    n = int(input())
    a = list(map(int, input().split()))
    ps = [a[0]]
    for i in range(1, n):
        ps.append(ps[i - 1] + a[i])
    ans = 0
    for i in range(n - 2, -1, -1):
        ans += a[i + 1] * ps[i]
        ans %= MOD
    print(int(ans))

t = 1
# t = int(input())
for i in range(1, t + 1):
    solve(i)

Submission status: Accepted

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

mod = 10 ** 9 + 7

s = 0
ans = 0

for i in a:
    ans += s * i
    ans %= mod
    s += i
    s %= mod

print(ans)

Submission status: Accepted

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

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

n = int(input())
a = lmp()
mod = int(1e9+7)
ans = 0
num = sum(a)
for i in range(n-1):
    u = num - a[i]
    ans += a[i] * u
    ans %= mod
    num = u
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

A = np.array(read().split(), np.int64)[1:]

x = A.sum() % MOD
y = (A * A % MOD).sum() % MOD
x = (x * x - y) % MOD
if x & 1:
    x += MOD
print(x // 2)

Submission status: Accepted

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

n = inp()
a = inpl()
b = []
now = 0
for i in range(n)[::-1]:
    now += a[i]
    now %= mod
    b.append(now)
b = b[::-1]
res = 0
for i in range(n-1):
    res += a[i]*b[i+1]
    res %= mod
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10**9+7

S = 0
T = 0
for a in A:
    S = (S+a  )%mod
    T = (T+a*a)%mod

ans = (S*S-T)%mod
print(ans*pow(2, mod-2, mod)%mod)

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = A[0]
    ans = 0
    for i in range(1, N):
        ans += S * A[i]
        ans %= MOD
        S += A[i]
        S %= MOD
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
a = sum(A) ** 2 % mod
b = sum([a * a for a in A]) % mod
p = mod - 2
bin_p = []
while p:
  bin_p.append(p % 2)
  p >>= 1
ret = 1
for j in reversed(bin_p):
  ret = (ret * ret) % mod
  if j == 1:
    ret = (ret * 2) % mod
print((a - b) * ret % mod)

Submission status: Accepted

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

S=[sum(A)]
for i in range(N):
    S.append(S[-1]-A[i])

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

Submission status: Accepted

Solution code:
from itertools import accumulate
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)

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

Submission status: Accepted

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

    total = (total + ( lst[i]*(s - cum) ) )%mod
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input());
X=list(map(int,input().split()))
s=0;t=0;
for i in range(N):
  s+=X[i];
  t+=X[i]*X[i];
print(((s*s-t)//2)%1000000007)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
sumA = 0
for ai in A:
    sumA = (sumA + ai) % MOD
ans = 0
for ai in A:
    sumA = sumA - ai
    ans = (ans + sumA * ai) % MOD

print(ans)

Submission status: Accepted

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

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

INF=10**9+7

s=0
for i in a:
    s=(s+i)%INF

d=0
for i in a:
    d=(d+i**2)%INF

ans=(s**2-d)%INF

def modinv(a,m):
    b=m
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while not b==0:
        q=a//b
        (a,b)=(b,a%b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx%m
ans=(ans*modinv(2,INF))%INF

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# sys.stdin  = open("input.txt")
n=int(input())
pref=[0]
mod=10**9
mod+=7
a=[int(o) for o in input().split()]
ans=0
for i in a:
    pref.append(pref[-1]+i)
    ans+=((i*pref[-2])%mod)
    ans%=mod

# print(pref)
print(ans%mod)

Submission status: Accepted

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

slist=[0]*N
sum_a=0
for i in reversed(range(N)):
  sum_a+=alist[i]
  slist[i]=sum_a  
#print(slist)

answer=0
for i in range(N-1):
  answer+=alist[i]*slist[i+1]
  answer%=MOD
  
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n):
    s += a[i]
    #s %= mod

for i in range(n):
    nizyo += a[i]**2
    #nizyo %= mod

print(((s**2 - nizyo)//2)%mod)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(((sum(a)**2 - sum([e**2 for e in a])) // 2) % (10**9 + 7))

Submission status: Accepted

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

mod = 10**9 + 7

summm = sum(nums) % mod
sum_square = sum([num ** 2 for num in nums]) % mod

ans = (summm ** 2 - sum_square) % mod
ans *= (mod + 1) // 2
ans %= mod
print(ans)

Submission status: Accepted

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

MOD = int(1e9 + 7)
res = 0
sum = 0

for n in v:
  res = (res + (n % MOD * sum) % MOD) % MOD
  sum = (sum + n) % MOD

print(res)

Submission status: Accepted

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