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: Time Limit Exceeded

Solution code:
n=int(input())
mod=int(1e9)+7
l=[int(x) for x in input().split()]
sum1=0
for i in range(n-1):
    for j in range(i+1,n,1):
        prod=(l[i]*l[j])%mod
        sum1=(sum1%mod+prod%mod)%mod
print(sum1)

Submission status: Time Limit Exceeded

Solution code:

x = (10**9)+7
n = int(input())
val = 0
lst = list(map(int,input().split()))
for value in lst:
    value = value%x
for i in range(n-1):
    for j in range(i+1,n):
        val += (lst[i]*lst[j])
        val = val%x
print(val)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def INT():
    return int(input())

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

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

N = INT()
A = LI()
mod = 10**9 + 7
ans = 0

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

Submission status: Time Limit Exceeded

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

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

print(ans%mod)

Submission status: Time Limit Exceeded

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

sm=0

for i in range(n-1):
  for j in range(i+1,n):
    b=a[i]*a[j]
    sm+=b
    sm=sm%((10**9)+7)

print(sm)

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

ans = 0

m = 10**9+7

for i in range(n):
  for j in range(i+1,n):
    ans = (ans + a[i]%m*a[j]%m)%m

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product, combinations

n = int(input())

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

result = 0

for x, y in combinations(a, 2):
	result += x * y

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-1):
    for j in range(i+1, n):

        a1 = a_lst[i]
        a2 = a_lst[j]
        ans += (a1 % (10 ** 9 + 7)) * (a2 % (10 ** 9 + 7))
        ans %= (10 ** 9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
li = list(map(int,input().split()))
asum = 0
newli = list(itertools.combinations(li,2))
for i in range(n*(n-1)//2):
    asum += newli[i][0]*newli[i][1]
    if asum >= 10**9 + 7:
        asum = asum % (10**9 + 7)
print(asum)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys,collections
from sys import stdin, stdout  
#MAXN = 10000001

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip() 
def input(): return sys.stdin.readline().strip()
#spf = [0 for i in range(MAXN)] 
def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 
def is_subsequence(x, y):
    """Test whether x is a subsequence of y"""
    x = list(x)
    for letter in y:
        if x and x[0] == letter:
            x.pop(0)

    return not x    
def sieve(): 
	spf[1] = 1
	for i in range(2, MAXN): 
		spf[i] = i 
	for i in range(4, MAXN, 2): 
		spf[i] = 2

	for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
		if (spf[i] == i): 
			for j in range(i * i, MAXN, i): 
				if (spf[j] == j): 
					spf[j] = i 
def getFactorization(x): 
	ret = list() 
	while (x != 1): 
		ret.append(spf[x]) 
		x = x // spf[x] 

	return ret 
def getFloor(A, x):

    (left, right) = (0, len(A) - 1)

    ind,floor = -1,-1
    while left <= right:
        mid = (left + right) // 2
        '''if A[mid] == x:
            return mid'''
        if x < A[mid]:
            right = mid - 1
        else:
            floor = A[mid]
            ind=mid
            left = mid + 1
            
    return ind
def check(st) : 
  
    # Compute sum of digits 
    n = len(st) 
    digitSum = 0
      
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i]) 
  
    # Check if sum of digits 
    # is divisible by 9. 
    return (digitSum % 9 == 0)     
def isPowerOfTwo(n): 
    if (n == 0): 
        return False
    while (n != 1): 
            if (n % 2 != 0): 
                return False
            n = n // 2
            
              
    return True
def kitte(n):
	c=0
	while(n!=0):
		n=n//2
		c+=1
	return c	
def aa(b,c):
	m=min(b,c)
	b-=m
	c-=m
	if(c>0 and b>0):
		return(m+((b+c)//3))
	else:
		return(m)
def bb(a,c):
	m=min(a,c)
	a-=m
	c-=m
	if(c>0 and a>0):
		return(m+((a+c)//3))
	else:
		return(m)
def cc(b,a):
	m=min(b,a)
	b-=m
	a-=m
	if(a>0 and b>0):
		return(m+((b+a)//3))
	else:
		return(m)		
#file()
#sieve() 
mod=(10**9)+7	
def main():
		n=int(input())
		l=get_array()
		s=0
		#n=len(l)
		for i in range(n):
			for j in range(i+1,n):
				a=l[i]%mod
				b=l[j]%mod
				s+=(a*b)%mod
		print(s%mod)		

	



	

	
			


		




		






		







			



	

	




	





















	




















		
			


		

			

		





			

	























				

	















	

	










if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(i+1,N):
    ans += A[i]*A[j]
    
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

tot = 0
for i in range(len(As)):
    for j in range(i+1,len(As)):
        tot = (tot + As[i]*As[j])%(10**9+7)

print(tot)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=((L[i]%mod)*(L[j]%mod))%mod
print(total%mod)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations
def main():
    n, *a = map(int, read().split())
    large_p = 10 ** 9 + 7
    a2 = [i % large_p for i in a]
    com = tuple(combinations(a2, 2))
    r = 0
    for come in com:
        r += (come[0] * come[1]) % large_p
        r = r % large_p
    print(r)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
c=0
for i in range(len(l)):
    for j in range(i+1,len(l)):
        c+=l[i]*l[j]
print(c%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	n = int(input())
	l = list(map(int, input().split()))
	_sum = 0
	for i in range(n):
		for j in range(i + 1, n):
			_sum += l[i] * l[j]
	mod = 10**9 + 7
	print(_sum % mod)

main()

Submission status: Time Limit Exceeded

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

print(ans%mod)

Submission status: Time Limit Exceeded

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

ans = 0
mod = 10**9 + 7
for i in range(n-1):
    for j in range(i+1,n):
        ans += (((x[i])%mod)*(x[j]%mod))%mod
        
print((ans)%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

x = (10**9)+7
n = int(input())
val = 0
lst = list(map(int,input().split()))
for i in range(n-1):
    for j in range(i+1,n):
        val += (lst[i]*lst[j])
        val = val%x
print(val)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys


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


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += A[i] * A[j] % mod
            ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
A = [int(i) for i in input().split(maxsplit=N)]
sumA = 0
for a, b in combinations(A, 2):
    sumA += (a * b) % (10**9 + 7)
print(sumA % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations
def main():
    n, *a = map(int, read().split())
    large_p = 10 ** 9 + 7

    com = tuple(combinations(a, 2))
    r = 0
    for come in com:
        r += (come[0] * come[1]) % large_p
        r = r % large_p

    print(r)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import sys,collections
from sys import stdin, stdout  
#MAXN = 10000001

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip() 
def input(): return sys.stdin.readline().strip()
#spf = [0 for i in range(MAXN)] 
def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 
def is_subsequence(x, y):
    """Test whether x is a subsequence of y"""
    x = list(x)
    for letter in y:
        if x and x[0] == letter:
            x.pop(0)

    return not x    
def sieve(): 
	spf[1] = 1
	for i in range(2, MAXN): 
		spf[i] = i 
	for i in range(4, MAXN, 2): 
		spf[i] = 2

	for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
		if (spf[i] == i): 
			for j in range(i * i, MAXN, i): 
				if (spf[j] == j): 
					spf[j] = i 
def getFactorization(x): 
	ret = list() 
	while (x != 1): 
		ret.append(spf[x]) 
		x = x // spf[x] 

	return ret 
def getFloor(A, x):

    (left, right) = (0, len(A) - 1)

    ind,floor = -1,-1
    while left <= right:
        mid = (left + right) // 2
        '''if A[mid] == x:
            return mid'''
        if x < A[mid]:
            right = mid - 1
        else:
            floor = A[mid]
            ind=mid
            left = mid + 1
            
    return ind
def check(st) : 
  
    # Compute sum of digits 
    n = len(st) 
    digitSum = 0
      
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i]) 
  
    # Check if sum of digits 
    # is divisible by 9. 
    return (digitSum % 9 == 0)     
def isPowerOfTwo(n): 
    if (n == 0): 
        return False
    while (n != 1): 
            if (n % 2 != 0): 
                return False
            n = n // 2
            
              
    return True
def kitte(n):
	c=0
	while(n!=0):
		n=n//2
		c+=1
	return c	
def aa(b,c):
	m=min(b,c)
	b-=m
	c-=m
	if(c>0 and b>0):
		return(m+((b+c)//3))
	else:
		return(m)
def bb(a,c):
	m=min(a,c)
	a-=m
	c-=m
	if(c>0 and a>0):
		return(m+((a+c)//3))
	else:
		return(m)
def cc(b,a):
	m=min(b,a)
	b-=m
	a-=m
	if(a>0 and b>0):
		return(m+((b+a)//3))
	else:
		return(m)		
#file()
#sieve() 
mod=(10**9)+7	
def main():
		n=int(input())
		l=get_array()
		s=0
		#n=len(l)
		for i in range(n):
			for j in range(i+1,n):
				s+=(l[i]*l[j])%mod
		print(s%mod)		

	



	

	
			


		




		






		







			



	

	




	





















	




















		
			


		

			

		





			

	























				

	















	

	










if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=((L[i]%mod)*(L[j]%mod))
print(total%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_num = list(map(int, input().split()))
res = 0
MOD = 10**9+7
for i in range(len(l_num)):
    for j in range(i+1, len(l_num)):
        res += l_num[i]*l_num[j]

print(res%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        total+=(L[i]*L[j])
print(total%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 +7
s = 0
for i in range(n):
    for j in range(i + 1, n):
        s += (a[i]%MOD * a[j]%MOD)%MOD
print(s%MOD)

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    for j in range(i+1, N):
        answer += A[i] * A[j] % mod
print(answer % mod)

Submission status: Accepted

Solution code:
def main(N, A):
    ans = 0
    culm = sum(A)
    for i in range(N-1):
        culm -= A[i]
        ans += A[i]*culm
        ans %= 10**9 + 7
    return ans

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [x*x for x in a]

#print(a)
#print(b)

s = sum(a)
s = s * s - sum(b)
s = s // 2
s = s % 1000000007

print(s)

# (a+b+c)^2 = a^2 + b^2 + c^2 + 2ab + 2ac + 2bc

Submission status: Accepted

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

Submission status: Accepted

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

all_sum = 0
count = 1

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
large_p = 10**9 + 7
from itertools import accumulate
def main():
    n, *a = map(int, read().split())
    a2 = [ae % large_p for ae in a]
    a2a = tuple(accumulate(a2))
    r = 0
    for i1 in range(n - 1):
        t0 = a2[i1] * (a2a[-1] - a2a[i1])
        r += t0
        r = r % large_p
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7 

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

S = sum(A) % MOD
ans = 0

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

ans %= MOD 
print(ans)

Submission status: Accepted

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

for i in range(num):
    val_sum = val_sum - val[i]
    ans     = val[i] * val_sum + ans
        
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-1):
    S -= a[i]
    ans += a[i]*S
    ans %= mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

B = []
b = 0
e = 10 ** 9 + 7

for i in range(N - 1):
    b += A[N - 1 - i]
    b = b % e
    B.append(b)

result = 0

for i in range(N - 1):
    result += A[i] * B[N - 2 - i]
    result = result % e

print(result)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sum_A = sum(A)
for i,ai in enumerate(A):
  sum_A -= ai
  total += ai * sum_A
print(total % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
k = int((10**9 + 8)/2)
sum = 0
sum_1 = 0

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

for j in range(N):
    sum_1 += A[j]**2
sum_1 = (sum_1)%mod

ans = sum - sum_1
ans = (ans*k)%mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n = int(input()) #入力
#a, b = (int(x) for x in input().split())
#a, b = map(int, input().split())

#G = [input() for i in range(0, H)] #文字列を複数行に渡って

#a = [int(x) for x in input().split()]
#a = list(map(int, input().split()))
#a = [list(map(int,input().split(" "))) for i in range(N)]   #2次元


#a.sort() # C++ の sort(a.begin(), a.end());
#a.append(3) # C++ の a.push_back(3);


#exit(0) # return 0 的な。終了できる。
## 整数の切り捨て除算は // (ダブルスラッシュ)


#a[始まりの位置: 終わりの位置: スライスの増分] # (a は配列)


#import numpy as np  #importに100 ms 程度かかる。
import math
import copy
import string
#math.gcd(a, b) で、gcd 計算できる。
#math.pi は円周率。

INF = int(10**18) #べき乗 C++ の pow(10, 18) or 1e18;
pi = math.pi

MOD = 1000000007
#MOD = 1000000009
#MOD = 998244353




#繰り返し2乗法
#N^aの、Mで割った余りを求める。
def my_pow(N, a, M):
    if(a == 0):
        return 1
    else:
        if(a % 2 == 0):
            tempo = my_pow(N, a/2, M)
            return (tempo * tempo) % M
        else:
            tempo = my_pow(N, a - 1, M)
            return (tempo * N) % M




#N_C_a を M で割った余り
def my_combination(N, a, M):
    res = 1

    for i in range(0, a):
        res *= N - i
        res %= M

    for i in range(0, a):
        res *= my_pow(i + 1, M - 2, M)
        res %= M

    return res




#N_C_i を M で割った余りを、v[i] に代入する。
def my_combination_table(N, M, v):
    if(len(v) < N + 1):
        l = N + 1 - len(v)
        tempo = [1] * l
        v.extend(tempo)

    for i in range(1, N + 1):
        v[i] = v[i - 1] * (N - (i - 1))
        v[i] %= M

        v[i] *= my_pow(i, M - 2, M)
        v[i] %= M

    return




#math.factorial で階乗は計算できる。
#math.gcd で gcd は計算できる。
#np.gcd.reduce(A) #(Aは配列) で、Aの全ての要素の gcd が計算できる。


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

sum = 0
sum2 = 0
for i in range(0, N):
    sum += A[i]
    sum2 += A[i] * A[i]
#

res = sum * sum - sum2
res //= 2
res %= MOD
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(count):
  sum = sum - a[i]
  ans += sum * a[i]
  
answer = ans % mod
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# f=open('in','r')
# input=lambda:f.readline().strip()

n=int(input())
r=list(map(int,input().split()))
mod=1000000007
s=sum(r)%mod
x=0
for u in r:
  x+=u**2
x%=mod
t=500000004
print((s**2-x)*t%mod)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())),dtype=np.longlong)
mod = 7+10**9
cs = 0
for a in A:
    cs += a
    cs %= mod
cumsum = np.mod(np.cumsum(A),mod)
rev = -1*(cumsum-cs)
ans = 0
for i in range(n-1):
    ans += rev[i]*A[i]
    ans %= mod
print(ans)

Submission status: Accepted

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

square_sum_ai = sum(ai) ** 2
sum_ai_square = sum(map(lambda x: x ** 2, ai))

print(((square_sum_ai - sum_ai_square) // 2) % (10 ** 9 + 7))

Submission status: Accepted

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

ans = 0
mod = 7 + 10**9

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

MOD = int(1e9+7)

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

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

print(ans)

Submission status: Accepted

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

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

for j in range(N):
    sum_1 += (A[j]**2)%mod
sum2=sum-sum_1
if sum2<0:
    sum2+=mod
ans=(sum2*500000004)%mod
print(int(ans))

Submission status: Accepted

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

cur = 0
res = 0
for i in range(n-1):
    cur = (cur + a[n-1-i]) % mod
    tmp = (a[n-2-i] * cur) % mod
    res = (res + tmp) % mod

print(res)

Submission status: Accepted

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

S = sum(A) % MOD
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy
n=int(input())
l=list(map(int, input().split()))
res=0
mod=10**9+7
l.append(0)
l.reverse()
cum=numpy.cumsum(l)%mod
for i in range(n):
    res+=((l[n-i]%mod)*cum[n-i-1])%mod
print(res%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7

s = sum(arr) % mod

result = 0
for i in arr:
  s -= i
  s %= mod
  result += s * i
  result %= mod
print(result)

Submission status: Accepted

Solution code:
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

val = 0
for a in A:
    val += a * sumA
    val %= 2 * MOD
for a in A:
    val -= a * a
    val %= 2 * MOD
val //= 2
val %= MOD
print(val)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    MOD = 10**9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = sum(a)
    ans = 0
    
    for i in range(n):
        ans += a[i] * (a_sum - a[i])
    print(ans // 2 % MOD)
        
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

mod = 10 ** 9 + 7


def cumsum(num, lst):

    cumsumlst = [0] * num

    for hoge in range(1, n):
        cumsumlst[hoge] = (cumsumlst[hoge-1] + lst[hoge]) % mod
    
    return cumsumlst

lst = cumsum(n, a)

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

MOD = 10 ** 9 + 7

tmp = 0

ans = 0

for num in A:
    ans += tmp * num % MOD
    tmp += num
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())

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

MOD = 10 ** 9 + 7

tmp = 0

ans = 0

for num in A:
    ans += tmp * num
    tmp += num
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())

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

MOD = 10 ** 9 + 7

max_edge = sum(A)

tmp = 0

for num in A:
    tmp += num ** 2

print((max_edge ** 2 - tmp) // 2 % MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    K = int(1e9)+7
    acum = [0]
    for i  in range(N):
        acum.append(acum[i]+A[i])
    ans = 0
    for i in range(N):
        ans += A[i]*(acum[N]-acum[i+1])
        ans %= K
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

M = 10**9 + 7

Total = sum(A) -A[0]

ans = 0

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

print(ans)

Submission status: Accepted

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

sum = 0
B = []
B.append(0)

for t in range(N):
    B.append(A[t] + B[t])
    
B.remove(0)
    
for i in range(N):
    sum += A[i] * (B[N-1] - B[i])
        
print(sum % (10**9+7))

Submission status: Accepted

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

cum = [0 for _ in range(N)]
cum[0] = A[0]
for i in range(N - 1):
    cum[i + 1] = (cum[i] + A[i + 1]) % mod

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

Submission status: Accepted

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

res = 0
ruiseki = 0
for j in range(n):
    if j == 0:
        continue
    ruiseki += a[j-1]
    res = res + a[j]*ruiseki
print(res % ((10 **9)+7))