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: Runtime Error

Solution code:
a = [list(map(int, input().split())) for i in range(2)]
sum = 0

for i in range(1,n):
  for j in range(i+1,n+1):
    sum += a[2][i] * a[2][j]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
num = int(input())
data = list(map(int, input().split()))
sum = 0
for i in range(num-1):
  sum = sum + data(i) * sum(data[i+1:])
print(sum)
num = int(input())
data = list(map(int, input().split()))
sum = 0
for i in range(num-1):
  for j in range(1, num):
    if i < j:
      sum = sum + data[i] * data[j]
if len(str(sum)) >= 10:
  sum = sum % (10**9 + 7)
print(sum)

Submission status: Runtime Error

Solution code:
num = int(input())
data = list(map(int, input().split()))
sum = 0
for i in range(num-1):
  for j in range(1, num):
    if i < j:
      sum = sum + data[i] * data[j]
	if len(sum) >= 10:
      sum = sum % (10**9 + 7)
print(sum)

Submission status: Runtime Error

Solution code:
num = int(input().split())
data = list(input().split())
sum = 0
for i in range(num-1):
  for j in range(1, num):
    sum = sum + data[i] * data[j]
print(sum//(10**9 + 7))

Submission status: Runtime Error

Solution code:
n=int(input())
arr=list(map(int, input().split()))
m=0
for i in range(n):
  for j in range(n):
    if i==j:
      pass
   	else:
      m+=(i*j)
print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
m = int(input())
a = input().split()
tmp = sum(int(n[0])*int(n[1]) for n in set([(a[i],w) for w in a[i+1:]] for i in range(m)))
print(tmp%1000000007)

Submission status: Runtime Error

Solution code:
m = int(input())
a = input().split()
l = [[(a[i],w) for w in a[i+1:]] for i in range(m)]
tmp = sum(int(n[0])*int(n[1]) for n in set(l))
print(tmp%1000000007)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
sum = 0
for sum_cnt in range(1, n):
    sum += a[sum_cnt]

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

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

print(ans

Submission status: Runtime Error

Solution code:
N = int(input())
Al = input().split()

A = range(N)
for i in range(Al):
  A[i] = int(i)

num = 0

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
ans = 0

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

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
products_matrix = np.zeros((N, N))
for i in range(N):
    for j in range(N):
        products_matrix[i, j] = A[i] * A[j]

products_sum = 0
for k in range(N):
    for l in range(N):
        if l > k:
            products_sum = products_sum + products_matrix[k, l]

mod = 10**9 + 7            
ans = int(products_sum % mod)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
products_matrix = np.zeros((N, N))
for i in range(N):
    for j in range(N):
        products_matrix[i, j] = A[i] * A[j]

products_sum = 0
for k in range(N):
    for l in range(N):
        if l > k:
            products_sum = products_sum + products_matrix[k, l]

mod = 10**9 + 7            
ans = int(products_sum % mod)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
products_matrix = np.zeros((N, N))
for i in range(N):
    for j in range(N):
        products_matrix[i, j] = A[i] * A[j]

products_sum = 0
for k in range(N):
    for l in range(N):
        if l > k:
            products_sum = products_sum + products_matrix[k, l]

mod = 10e+9 + 17            
ans = int(products_sum % mod)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
products_matrix = np.zeros((N, N))
for i in range(N):
    for j in range(N):
        products_matrix[i, j] = A[i] * A[j]

products_sum = 0
for k in range(N):
    for l in range(N):
        if l > k:
            products_sum = products_sum + products_matrix[k, l]

mod = 10e+9 + 17            
ans = products_sum % mod
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = 0
ans 
for i in range(N):
  S += A[i]
  
for i in range(N):
  ans += S * A[i]
  
print(ans)

Submission status: Runtime Error

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
import numpy 
 
def main():
    n = int(input())
    alist = list(map(int, input().split()))
    max_num = 10**9 + 7
    ans = 0
    for i in range(n):
        ans += numpy.cumsum(alist[:i+1])

    print(ans%max_num)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s,t=int(input()),input()
t,j,sum=t.split(),0,0
a=list(range(100))
for i in range(s):
    a[j]=int(t[i])
    j=j+1
for k in range(s):
    for y in range(k+1,s):
        sum=sum+a[k]*a[y]
print(sum)

Submission status: Runtime Error

Solution code:
def main():
    mod = 10**9+7
    #n,a = get_input()
    n = int(input())
    a = [int(x) for x in input().split()]
    aa = [a**2 % mod for x in a]
    ans = 0
    asum = sum(a) 
    p = asum ** 2 % mod
    q = sum(aa) % mod
    ans = (p - q) % mod
    if ans < 0:
      ans += mod
    if ans % 2 == 1:
      ans += mod
    ans = ans // 2
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
L=[int(x) for x in input().split()]
sum=0
product=0
mod=1000000007
for i in range(n):
    sum+=L[i]%mod
for i in range(n-1):
    sum-=(L[i]%mod)
    product+=sum*(L[i]%mod)
print(product)

Submission status: Runtime Error

Solution code:
L=[int(x) for x in input().split()]
sum=0
product=0
mod=1000000007
for i in range(n):
    sum+=L[i]%mod
for i in range(n-1):
    sum-=(L[i]%mod)
    product+=sum*(L[i]%mod)
print(product)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
mod = 10**9+ 7
a = list(map(int,input().split()))
ans = (sum(a)%mod)**2 - (sum[x**2 for x in a]%mod)
ans *= 5*10**8+4
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

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

Submission status: Runtime Error

Solution code:
import numpy as np

MOD = 10 ** 9 + 7

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

# 累積和を求める

# 例
# [1,2,3,4,5,6]の時、累積和は、
# [0,1,3,6,10,15,21]

s=np.cumsum(alst,dtype='list')

sum=0

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

print(sum%MOD)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
const int N = 2e5+5;
const int mod = 1e9+7;
typedef long long ll ;
ll s[N],arr[N];


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int num;
    cin>>num;
    for(int i = 1;i<=num;i++)
    {
        ll temp;
        cin>>temp;
        arr[i]=temp;
        if(i==1)
            s[i]=temp;
        else
            s[i]=(s[i-1]+temp);
    }
    ll he = 0;
    for(int i =1;i<=num-1;i++)
    {
        ll temp =(s[num]-s[i])*arr[i]%mod;
        he+=temp;
        he=he%mod;
    }
    cout<<he;


}

Submission status: Runtime Error

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

from itertools import combinations

mod = 1000000007  # 丁度いい大きさの素数だけで意味は特にない。
s = 0
for c in combinations(A, 2):
    s += c[0] * c[1]

print(s % mod)

Submission status: Runtime Error

Solution code:
n=int(input())
array=list(map(int,input().split()))
list2=[]
for i in range(n-1):
  for j in range(i+1,n):
    list2.append(array[i]*array[j])
a=n*(n-1)/2
ans=0
for m in range(a):
  ans=ans+list2[m]
  if ans>=10**9+7:
    ans=ans-(10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
array=list(map(int,input().split()))
list2=[]
for i in range(n):
  for j in range(i+1,n):
    list2.append(array[i]*array[j])
a=n*(n-1)/2
ans=0
for m in range(a):
  ans=ans+list2[m]
  if ans>=10**9+7:
    ans=ans-(10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
array=list(map(int,input().split()))
list2=[]
for i in range(n):
  for j in range(i+1,n):
    list2.append(array[i]*array[j])
a=n*(n-1)
ans=0
for m in range(a):
  ans=ans+list2[m]
  if ans>10**9+7:
    ans=ans-10**9+7
print(ans//10**9+7)

Submission status: Runtime Error

Solution code:
sus = 0

for i in a:
    su = su - i
    sus = sus + i * su

"""comb = len(a) * (len(a) - 1) / 2
comb = int(comb)

sum = 0
la = len(a)

for i in range(comb):
    #print(a)
    for j in range(1, la):
        #print(a[i])
        sum = sum + a[0] * a[i]
    a = a[1:]
    la = la - 1
    #print(a)"""

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

Submission status: Runtime Error

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

A = A % (1*10**9 + 7)
value = 0
plus = 0
ans = 0

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

print(value)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []  # 累積和テーブル B[i] = sum(A[:i])
mod = 10**9 + 7
ans = 0

for i in range(N):
    B[i+1] = B[i] + A[i]  # 累積和

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split())
B = []  # 累積和テーブル B[i] = sum(A[:i])
mod = 10**9 + 7
ans = 0

for i in range(N+1):
    B.append(sum(A[:i]))  # 累積和

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

print(ans)

Submission status: Runtime Error

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

MOD = 10**9 + 7

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

print(total % MOD)

Submission status: Runtime Error

Solution code:
n=input()
m=0
from itertools import combinations
b=combinations
a=b(map(int,input().split()),2)
for i,j in a:
    k=i*j
    m+=k
if m<=MOD:
    print(m)
else:
	MOD=10**9+7
    v=m%MOD
    print(v)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#標準入力
N = int(input())
A = list(map(int, input().split()))
 
#累積和
S = [0]*N
for n in range(N):
  S[n] = S[n-1] + A[n]
  
_sum = int(0)
for i in range(N-1):
  _sum = _sum + int((A[i] * (S[N] - S[i])))

#modulo
_sum = _sum % (1000000000+7)
  
print(_sum)

Submission status: Runtime Error

Solution code:
#標準入力
N = int(input())
A = list(map(int, input().split()))
 
#累積和
S = [0]*N
for n in range(N):
  S[n] = S[n-1] + A[n]
  
_sum = 0
for i in range(N-1):
  _sum = _sum + (A[i] * (S[N] - S[i+1]))

#modulo
_sum = _sum % (1000000000+7)
  
print(_sum)

Submission status: Runtime Error

Solution code:
#標準入力
N = int(input())
A = list(map(int, input().split()))
 
#累積和
S = [0]*N
for n in range(N):
  S[n] = S[n-1] + A[n]
  
_sum = 0
for i in range(N-1):
  _sum = _sum + (A[i] * (S[N] - S[i+1]))
  _sum = _sum % (1000000000+7)
  
print(_sum)

Submission status: Runtime Error

Solution code:
#標準入力
N = int(input())
A = list(map(int, input().split()))

#累積和
S = [0]*N
for n in range(N):
	S[n] = S[n-1] + A[n]

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

Submission status: Runtime Error

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

def square(x):
  return x * x

out = (square(sum(nums)) - sum(map(square, nums))) / 2

return out

Submission status: Runtime Error

Solution code:
import itertools

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

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

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
 
N = int(input())
A = np.array(map(int, input().split()))
 
A %= (1000000000+7)
_sum = 0
 
for n in range(N-1):
  for i in range(n+1):
    _sum += A[n+1] * A[i]
    _sum %= (1000000000+7)
    
print(_sum)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(map(int, input().split()))

A %= (1000000000+7)
_sum = 0

for n in range(N-1):
  for i in range(n+1):
    _sum += A[n+1] * A[i]
    _sum = %= (1000000000+7)
    
print(_sum)

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

Submission status: Runtime Error

Solution code:
MOD = 1000000007

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

print(n_list)

result = 0

for i in range(n):
    for j in range(n-i-1)
        result += n_list[i] * n_list[j+1] % MOD
        result = result % MOD

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
M=10**9+7
N=int(input())

Alist=np.array([int(i) for i in input().split()])

Amat=np.outer(Alist,Alist)
Atri=Amat[np.nonzero(np.tril(Amat,k=-1))]
sumsum=np.sum(Atri)%M
print(sumsum)

Submission status: Runtime Error

Solution code:
import numpy as np
M=10**9+7
N=int(input())

Alist=np.array([int(i) for i in input().split()])

Amat=np.outer(Alist,Alist)
Atri=np.tril(Amat,k=-1)
sumsum=np.sum(Atri)%M
print(sumsum)

Submission status: Runtime Error

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

mod= 10**9+7

A = sum(a)

ans=0

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

Submission status: Runtime Error

Solution code:
# -*- using:utf-8 -*-
from itertools import combinations

if __name__ == "__main__":
  n = int(input())
  li = list(map(int, input().split()))
  array = list(combinations(li, 2))
  sum = 0
  for i in range(n):
    sum += array[i][0] * array[i][1]
  print(sum)

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())
li = list(map(int, input().split()))
array = list(itertools.combinations(li, 2))
sum = 0
for i in range(n):
  sum += array[i][0] * array[i][1]
print(sum)

Submission status: Runtime Error

Solution code:
# -*- using:utf-8 -*-
import itertools

if __name__ == "__main__":
  n = int(input())
  li = list(map(int, input().split()))
  array = list(itertools.combinations(li, 2))
  sum = 0
  for i in range(n):
    sum += array[i][0] * array[i][1]
  print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
double = 0

for i in a:
    double += i*i

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split(" ")))
s = 0
for i in range(0,N):
  s += a[i]

s = s*s

for i in range(0,N):
  s -= a[i]*a[i]

if s % 2 = 0:
  s = s % 2*(10**9 +7)
  s = s/2
else:
  s = (s + 10**9 + 7) % 2*(10**9 + 7)
  s = s/2
 
print(int(s))

Submission status: Runtime Error

Solution code:
m = 1000000007

n = int(input())
a = map(int,input().split())
s = []

for i in range(n-1):
    for j in range(i+1,n):
        #print(a[i],a[j])
        s.append(a[i]*a[j])

ans = sum(s) % m
print(ans)

Submission status: Runtime Error

Solution code:
x = 10 ** 9 + 7

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += l[i] * l[j]

print(ans)

Submission status: Runtime Error

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

tmp = 0
tmp2 = 0

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

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define fr(i,c,b) for(int i=c;i<b;i++)
#define frl(i,c,b) for(ll i=c;i<b;i++)
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MAX 100001
#define M 1000000007
#define pb push_back

typedef long long int ll;

using namespace std;

int main()
{
    sll(n);
    ll a[n]; fr(i,0,n)  cin>>a[i];
    ll sum[n];
    sum[n-2]=a[n-1];
    for(int i=n-3;i>=0;i--)
    {
        sum[i]=sum[i+1]+a[i+1];
    }
    
    ll ans=0;
   // ll j=n-2;
    for(int i=0;i<n-1;i++)
    {
        ans=(ans%M+a[i]%M*sum[i]%M)%M;
    }
    
    cout<<ans%M;
    
    
    
}

Submission status: Runtime Error

Solution code:
mod = 10 ** 9 + 7
n = int(input())

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(p // 2) % mod * res % mod)

Submission status: Runtime Error

Solution code:
i = 0
j = i+1
ans = 0
while i != n - 1:
    ans = (ans+(a[i] * a[j])) % 1000000007
    j += 1
    if j == n:
        i += 1
        j = i + 1
print(ans)

Submission status: Runtime Error

Solution code:
i = 0
j = i+1
ans = 0
while i != n - 1:
  ans += a[i] * a[j]
  j += 1
  if j == n:
    i += 1
    j = i + 1
print(ans % 1000000007)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
print(a[0])
else:
l=list(map(lambda z:z**2,a)
x=sum(a)
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    long long ans = 0, sum =0;
    int mod = 1000000000+7;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        sum += a.at(i);
        sum %= mod;
    }
    for (int i = 0; i < N; i++) {
        sum -= a.at(i);
        if(sum<0) sum += mod;
        ans += sum * a.at(i);
        ans %= mod;
    }
    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    long long ans = 0, sum =0;
    int mod = 1000000000+7;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    for (int i = 0; i < N-1; i++) {
        sum -= a.at(i);
        if(sum<0) sum += mod;
        ans += sum * a.at(i);
        ans %= mod;
    }
    cout << ans << endl;
}
/*

*/

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a)
x=sum(a)
y=sum(l)
t=(x-y)//2
print(t)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
print(a[0])
else:
l=list(map(lambda z:z**2,a)
x=sum(a)
y=sum(l)
t=(x-y)//2
print(t)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(sumpro%mod)

Submission status: Runtime Error

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

Sum = sum(A)

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

ans %= 1000000007

print(int(ans/2))

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    mod = 10**9+7
    # a_sum = sum(A)
    a_cum = [0] * (n+1)
    for i in range(n):
        a_cum[i + 1] = a_cum[i] + A[i]
    ans = 0
    for i in range(len(A)-1):
        ans += A[i] * (a_cum[n] - a_cum[i+1]) % mod
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

n = int(input())
A = [int(x) for x in input().split()]
mod = 10**9+7
# a_sum = sum(A)
a_cum = [0] * (n+1)
for i in range(n):
    a_cum[i + 1] = a_cum[i] + A[i]
ans = 0
for i in range(len(A)-1):
    ans += A[i] * (a_cum[n] - a_cum[i+1])
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
mport numpy as np
from decimal import Decimal
N = int(input())
numbers = np.array(list(map(int, input().split())), dtype=Decimal)
square = numbers.sum()**2
numbers_pow = numbers**2
times_sum = (square - numbers_pow.sum()) / 2
print(int(times_sum % (1e9 + 7)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
ii, jj = np.meshgrid(range(N), range(N))
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
times_sum = np.where(ii < jj, times, 0).sum()
print(int(times_sum % (1e+9 + 7)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
ii, jj = np.mgrid[:N, :N]
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
times_sum = np.where(ii < jj, times, 0).sum()
print(int(times_sum % (1e9 + 7)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
ii, jj = np.meshgrid(range(N), range(N))
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
times_sum = np.where(ii < jj, times, 0).sum()
print(int(times_sum % 1000000007))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
ii, jj = np.mesehgrid(range(N), range(N))
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
times_sum = np.where(ii < jj, times, 0).sum()
print(int(times_sum % 1000000007))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
ii, jj = np.mgrid[:N, :N]
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
times_sum = np.where(ii < jj, times, 0).sum()
print(int(times_sum % (1000000007)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
ii, jj = np.mgrid[:N, :N]
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
times_sum = np.where(ii < jj, times, 0).sum()
print(int(times_sum % (1e+9 + 7)))

Submission status: Runtime Error

Solution code:
mport sys
import numpy as np
import math
import collections
import copy
import decimal
import itertools
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations

# input = sys.stdin.readline
N = int(input())
An = list(map(int, input().split()))
An_l = list(itertools.accumulate(An))
An_l.insert(0, 0)
ans = 0
for i, A in enumerate(An):
    tt = An_l[-1] - An_l[i+1]
#     print(i, An_l[-1], An_l[i], tt)
    At = A * tt
#     print(A, tt, At)
    ans = (ans+At) % (10**9+7)
#     print(ans)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
m=1000000007
n=int(input())
a=np.array(list(map(int,input().split())))
aa=np.ravel(np.triu(np.outer(a,a),k=1))%m
ans=0
for a in aa:
    ans+=a
    ans%=m
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
m=1000000007
n=int(input())
a=np.array(list(map(int,input().split())))
aa=np.outer(a,a)[np.triu_indices(n,k=1)]%m
ans=0
for a in aa:
    ans+=a
    ans%=m
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
using namespace std;

const unsigned int M = 1000000007;
int  N;

int main(){
    cin >> N;
    vector<long long> A;
    for(int i = 0; i < N; i++){
        long long x; 
        cin >> x;
        A.push_back(x);
    }

    long long sum = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            long long add = A[i] * A[j];
            sum += add;
            sum = sum % M;
        }
    }
    cout << sum << endl;
}

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    ll sums = 0;

    ans = 0;

    for (int i = 0; i < n; i++)
    {
        sums += a[i];
    }

    ans += (sums%mod) * (sums%mod);

    for (int i = 0; i < n; i++)
    {
        ans -= (a[i] * a[i]) % mod;
    }

    if(ans < 0) {
        ans += mod;
    }
    ans %= mod;

    ans *= (1.0/2);
    ans %= mod;

    cout << ans  << endl;
}

/*
int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    vector<ll> b(n-1);
    rep(i,n) {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    for (int i = 1; i < n; i++)
    {
        sum += a[i];  
    }


    int i = 1;
    for(int j = 0; j < n - 1; j++) {
        b[j] = sum;
        sum -= a[i++];
    }

    for(int i = 0; i < n - 1; i++) {
        ans += (b[i]%mod)*(a[i]%mod);
        ans %= mod;
    }



    cout << ans << endl;

}
*/

Submission status: Runtime Error

Solution code:
num = int(input())

line = input()
arr = [int(x) for x in line.split(" ")]

post = []
post[num - 1] = arr[num - 1]
for i in range(2, num + 1):
  post[num - i] = post[num-i+1] + arr[num - i]
  
sum = 0

for i in range(num-1):
  sum += arr[i] * post[i+1]
  sum %= 1e9 + 7
  
print(int(sum))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(1,n):
  l[i] += l[i-1]
i = 0
while i<n-1:
  ans += l[i]*(l[n] - l[i])
  i += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

sigma = sum(a)
count = 0
for i in range(len(a)-1):
  start = a[i]
  sigma = sigma-a[i]
  count = count + start * 
  if count >= 10**9+7:
    count = count % (10**9+7)

print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
A2=0
for i in ragne(len(A)):
  A2+=A[i]**2
c=(sum(A))**2-A2
print(c//2)

Submission status: Runtime Error

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