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:
N = int(input())
a = list(map(int, input().split()))
import numpy as np
a_ = np.array(a).reshape(-1, len(a))
all = np.dot(a_.T, a_)
taikaku = np.sum(np.diag(all))
all_ = np.sum(all)
if int(all_-taikaku)/2 >= (10**9+7):
    print(int((all_-taikaku)/2) % (10**9+7))
else:
    print(int((all_-taikaku)/2))

Submission status: Runtime Error

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

import numpy as np

mod = 10**9 + 7

def pairwise_combs_mask(a):
    a = np.array(a, dtype=np.int64)
    n = len(a)
    L = n*(n-1) // 2
    out = np.empty((L,2), dtype=a.dtype)
    m = ~np.tri(len(a), dtype=bool)
    out[:,0] = np.broadcast_to(a[:,None],(n,n))[m]
    out[:,1] = np.broadcast_to(a,(n,n))[m]
    return out

comb = pairwise_combs_mask(A)

summa = 0
for c in comb:
    summa += c[0] * c[1]

print(int(summa % mod))

Submission status: Runtime Error

Solution code:
import sys
n = int(input())

a = (list(map(int, input().split())))
dx = 10 ** 9 + 7

a = [i % dx for i in a if i != 0]

ans = 0
alist = []
for i in range(n):
    for j in range(i+1, n):
        alist.append((a[i] * a[j]) % dx)

for i in range(len(alist)):
    ans += alist[i]
    ans %= dx

ans %= dx
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/


int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long Asum=0;
  rep(i,N){
    cin>>A[i];
    Asum+=A[i];
  }
  long long sum=0;
  long long mod = pow(10,9)+7;
  for(int i=0;i<N;i++){
    Asum-=A[i];
    sum+=(A[i]*Asum)%mod;
    if(sum>=mod){
      sum%=mod;
    }
  }
  cout<<sum;
  return 0;
}

Submission status: Runtime Error

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

import numpy as np

mod = 10**9 + 7

def pairwise_combs_mask(a):
    a = np.array(a, dtype=np.float64)
    n = len(a)
    L = n*(n-1)//2
    out = np.empty((L,2), dtype=a.dtype)
    m = ~np.tri(len(a),dtype=bool)
    out[:,0] = np.broadcast_to(a[:,None],(n,n))[m]
    out[:,1] = np.broadcast_to(a,(n,n))[m]
    return out

comb = pairwise_combs_mask(A)

summa = 0
for c in comb:
    summa += c[0] * c[1]

print(int(summa % mod))

Submission status: Runtime Error

Solution code:
test = int(input())
for t in range(test):
    lst = map(int, input().split())
    lst2 = list(lst)
    sum = 0
    for i in range(len(lst2)):
        for j in range(i+1, len(lst2)):
            sum = sum + lst2[i] * lst2[j]
    print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
NUM = 1000000007
A = [int(input()) for _ in range(N)]
MASS = 0
for i in range (N):
    I = A[i] % NUM
    I = (I * (N - 1)) % NUM
    MASS += I
print(MASS % NUM)

Submission status: Runtime Error

Solution code:
n = int(input())
a = set(list(map(int, input().split())))
mod = 1000000007
res = 0


for i in range(n - 1):
    main = a.pop(0)
    res =  (res + main * sum(a) % mod) % mod
print(res)

Submission status: Runtime Error

Solution code:
x=int(input())
lst=[]
for i in range(x):
  lst.append(map(int,input().split()))
sum=0
for i in range(x):
    for j in range(1,x):
        sum=sum+(lst[i]*lst[j])
print(sum)

Submission status: Runtime Error

Solution code:
# This is a sample Python script.

# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)

n = int(input())
numbers = list(map(int, input().split())).sort()

for i in range(n):
    is_pair_wise_coprime = True
    for j in range(i + 1, n):
        if math.gcd(numbers[i], numbers[j]) != 1:
            is_pair_wise_coprime = False
            break
    if not is_pair_wise_coprime:
        break
else:
    print('pairwise coprime')
    exit(0)

if gcd(numbers) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Submission status: Runtime Error

Solution code:
import decimal


def resolve():
    n = int(input())
    A = list(map(decimal.Decimal, input().split()))
    A_sum = sum(A)
    ind_sum = 0
    for a in A:
        ind_sum += a**2

    print((A_sum**2 - ind_sum)//2 % (10**9 + 7))

resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
const long long INF = 10e9+7; 
string multiply(string num1, string num2) 
{ 
    int len1 = num1.size(); 
    int len2 = num2.size(); 
    if (len1 == 0 || len2 == 0) 
    return "0"; 
    vector<int> result(len1 + len2, 0); 
    int i_n1 = 0;  
    int i_n2 = 0;  
    for (int i=len1-1; i>=0; i--) 
    { 
        int carry = 0; 
        int n1 = num1[i] - '0'; 
        i_n2 = 0;               
        for (int j=len2-1; j>=0; j--) 
        { 
            int n2 = num2[j] - '0'; 
            int sum = n1*n2 + result[i_n1 + i_n2] + carry; 
            carry = sum/10; 
            result[i_n1 + i_n2] = sum % 10; 
            i_n2++; 
        } 
   
        if (carry > 0) 
            result[i_n1 + i_n2] += carry; 
        i_n1++; 
    }  
    int i = result.size() - 1; 
    while (i>=0 && result[i] == 0) 
    i--; 
    if (i == -1) 
    return "0"; 
    string s = ""; 
      
    while (i >= 0) 
        s += std::to_string(result[i--]); 
  
    return s; 
} 
  
int main()
{
	long long n,sum=0,product;
	cin>>n;
	vector<long long> num(n);
	for(auto& x:num)
	{
		cin>>x;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			product = stoll(multiply(to_string(num[i]),to_string(num[j]))) % INF;
			sum=sum+product;
			sum = sum % INF;
		}
	}
	cout<<sum;
	return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
n = 10 ** 9 + 7
A_n = np.array([int(i) % n for i in input().split()])
A_n_mod = np.sum([(A_n[i] * A_n[j]) % n for i in range(N-1) for j in range(i+1, N, 1)])
res = A_n_mod % n
print(res)

Submission status: Runtime Error

Solution code:
mo=1000000007
def fin(A,n):
	su=0;
	pro=0;
	for i in range(0,n):
		su=(su%mo+A[i]%mo)%mo
		pro=(pro%mo+((A[i]%mo)*(A[i]%mo))%mo)%mo
	ans=((su%mo)*(su%mo)-pro+mo)%mo
	return ans/2	

A=[]
n=int(input())
for i in range(0,n):
	ele=int(input())
	A.append(ele)
print(fin(A,n))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main()
{
    const long long MOD = (1000000000 + 7);

    int N;
    cin >> N;
    vector<unsigned long long> vec(N);
    unsigned long long v;
    for (int i = 0; i < N; i++) {
        cin >> v;
        vec[i] = v;
    }

    vector<unsigned long long> results;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            //printf("(%d, %d)\n", i, j);
            v = (vec[i] * vec[j]);
            results.push_back(v);
        }
    }

    unsigned long long result = 0;
    for (auto it = results.begin(); it != results.end(); ++it) {
        result += *it % MOD;
    }

    cout << result % MOD << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
u=0
u=int(input())
A = map(int,input().split())
n = len(A)
prr = 0
for i in range(n):
    for j in range(i + 1, n):
        prr = prr + A[i] * A[j]
print(prr)

Submission status: Runtime Error

Solution code:
n=int(input()) 
l=list(map(int,input().split())) 
s=0
for i in range(len(l)): 
  while(j!=len(l)): 
    for j in range(i+1,len(l)): 

      s=s+(l[i]*l[j]) 
print(s%((10**9)+7))

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int, input().split())
s=0
mod=(10**9)+7
for i in l:
	for j in l:
		if(i!=j):
			s=s+(i*j)
print(s%mod)

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;
#define M 1000000007
int main()
{
	long long a[200000], i,n, j, s=0, su=0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		s=(s+a[i])%M;
	}
	for (i = 0; i < n; i++)
	{
		s -= a[i];
		s+=M;
		s%=M;
		su += (a[i] * s)%M;
		su %= M;
	}
	cout << su;
}

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
import numpy as np
a_ = np.array(a).reshape(-1, len(a))
all = np.dot(a_.T, a_)
taikaku = np.sum(np.diag(all))
all_ = np.sum(all)
print(int((all_-taikaku)/2) % (10**9+7))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = a.reshape(1, -1)
Asq = np.transpose(A) @ A
Asq = np.triu(Asq) - np.diag(np.ndarray.diagonal(Asq))
Asq = Asq % (10**9+7)

print(np.sum(Asq) % (10**9+7))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

n=int(input())
sum=0
a=list()
for i in range(0,n):
    b = int(input())
    a.append(b)    
    
i =0
j=i+1

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

val=math.pow(10,9)+7
sum = np.mod(sum,val)
print (int(sum))

Submission status: Runtime Error

Solution code:
n= int(input())
lst = [int(i) for i in input().split()]
lst = sorted(lst)
count = 0
d_lst = []
for i in range(len(lst)):
    if lst[i] not in d_lst:
        if lst[i] == lst[i+1]:
            d_lst.append(lst[i])
for d in d_lst:
    count += d**2
lst = list(set(lst))

for i in range(len(lst)):
    for j in range(i+1,len(lst)):
        a = lst[i] * lst[j]
        count += a

if count > ( 10**9 + 7 ):
    print(count % (10**9 + 7))
else:
    print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
inputValue= input()
l=inputValue.split(" ")
result= 0
for i in range(N):
	for j in range(i+1, N):
		result=result+ int(l[i])* int(l[j])

print result%1000000007

Submission status: Runtime Error

Solution code:
def main():
    input()
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()
	xxx=False
    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x=int(input())
lst=[]
for i in range(x):
  lst.append(int(input()))
sum=0
for i in range(x):
    for j in range(1,x):
        sum=sum+(lst[i]*lst[j])
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
NUM = 1000000007
A = [list(map(int, input().split())) for _ in range(N)]
MASS = 0
for i in range (N):
    I = A[i] % NUM
    I = (I * (N - 1)) % NUM
    MASS += I
print(MASS % NUM)

Submission status: Runtime Error

Solution code:
inport numpy as np
N = int(input())
Sum = []
A = list(map(int, input().split()))
Sum = [A[i]*A[j] for j in range(N) for i in range(j)]
print(np.array(Sum).sum()%(1000000000+7))

Submission status: Runtime Error

Solution code:
n= int(input())
lst = [int(i) for i in input().split()]
lst = sorted(lst)
count = 0
d_lst = []
for i in range(len(lst)):
    if lst[i] not in d_lst:
        if lst[i] == lst[i+1]:
            d_lst.append(lst[i])
for d in d_lst:
    count += d**2
lst = set(lst)

for i in range(len(lst)):
    for j in range(i+1,len(lst)):
        a = lst[i] * lst[j]
        count += a

if count > ( 10**9 + 7 ):
    print(count % (10**9 + 7))
else:
    print(count)

Submission status: Runtime Error

Solution code:
def main():
    from sys import stdin
    readline = stdin.readline

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

    total =  0

    for i in range(N):
        An = int(A.pop())
        total += (sum(An * A))

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

main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())), dtype=int)
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
eye_r = (np.eye(N) + 1) % 2
times_sum = (times * eye_r / 2).sum()
print(int(times_sum) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
array_sum = 0
for i in range(0, n, 1):
    array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum += A[i] * A[i] 
print(((array_sum_square - individual_square_sum)% 1000000007) / 2)

Submission status: Runtime Error

Solution code:
#C
import numpy as np
n  = int(input())
a_ls = list(map(int, input().split()))

a_ls = (np.array([a_ls]))%(10**9+7)
a_ls2 = (np.array(a_ls).T)
tmp = np.dot(a_ls2, a_ls)%(10**9+7)
tmp = np.tril(tmp)
ans = (np.sum(tmp) - np.sum(np.diag(tmp)))%(10**9+7)
print(int(ans))

Submission status: Runtime Error

Solution code:
import operator
import numpy as np

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

print(data.cumprod()[-1])

Submission status: Runtime Error

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

ans = 1
res = 0

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

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

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

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

print(res)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
void solve(){
	unsigned long long mod=1000*1000*1000+7;
	unsigned long long n;
	cin>>n;
	unsigned long long a[n];
	for (unsigned long long i=0; i<n; i++) cin>>a[i];
	unsigned long long su=0,m=0;
	for (unsigned long long i=0; i<n; i++){
		su+=a[i];
		m+=a[i]*a[i];
	}
	unsigned long long ans=su*su-m;
	ans/=2;
	cout<<ans%mod;
}
int main(){
	solve();
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input()
lis = list(map(int,input()))
def sol(lis):
    MAX = 10**9+7
    s = 0
    for i in lis:
        s = (s%MAX)+i%MAX
    r = 0
    sq = (s%MAX)*(s%MAX)
    for i in lis:
        r = (r%MAX)+(i%MAX)*(i%MAX)
    r = (sq-r)//2
    r%=MAX
    print(r)
sol(lis)

Submission status: Runtime Error

Solution code:
x=int(input())
lst=[]
for i in range(x):
  lst.append(int(input())
sum=0
for i in range(x):
    for j in range(1,x):
        sum=sum+(lst[i]*lst[j])
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
array_sum = 0
for i in range(0, n, 1):
    array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum += A[i] * A[i] 
print(int((array_sum_square - individual_square_sum) % 1000000007) / 2)

Submission status: Runtime Error

Solution code:
N = int(input())
An = list(map(int, input().split()))
An_s = collections.Counter(An)
total = 0
for k in An_s:
    total += k
ans = 0
for A, v in An_s.items():
    At = A * (total-A)*v
#     print(A, total, At, ans)
    ans = (ans+At) % (10**9+7)
#     print(ans)
print(ans//2)

Submission status: Runtime Error

Solution code:
n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]

total = 0
for i in range(0, len(a_list)-1):
    print(a_list[i], a_list[i+1:])
    total += a_list[i] * sum(a_list[i+1:])
total = total % max
print(total)

Submission status: Runtime Error

Solution code:
n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]

print(sum(a_list))
total = 0
for i in range(0, len(a_list)-1):
    print(a_list[i], a_list[i+1:])
    total += a_list[i] * sum(a_list[i+1:])
total = total % max
print(total)

Submission status: Runtime Error

Solution code:
import numpy as np
def main():
  m=1000000007
  n=int(input())
  a=np.array(list(map(int,input().split())))
  b=np.outer(a,a)
  c=np.sum(b)
  d=np.dot(a,a)
  e=c-d
  e=e//2
  print(e%m)
main()

Submission status: Runtime Error

Solution code:
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
def rec(num):
  if len(num) == 2:
      return num[0] * num[1]
  else:    
    return (num[0] * sum(num[1:])) + rec(num[1:])
print(rec(num) % mod)

Submission status: Runtime Error

Solution code:
n = int(input())
l =[]
x = 10e9+7
product=0
sum=0
for a in range(n):
	b = int(input())
	l.append(b)
for i in range(n):
	for j in range(i+1,n):
		product = int(l[i])*int(l[j])
		sum = sum+product
sum = sum % x
print(sum)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":

    n = int(input())
    y = list(input().split())
    # print(y)
    x = [int(x) for x in y]
    # print(n)
    # print(x)
    test1 = list(itertools.combinations(x,2))


    test2 = 0
    for el in test1:
        test3 = el[0]
        for i in range(1, len(el)):
            test3 *= el[i]
        test2 += test3

    print(test2)

Submission status: Runtime Error

Solution code:
input()
lis = list(map(int,input().split()))
def sol(lis):
	MAX = 10**9+7
  	s = sum(lis)
    s%=MAX
    r = 0
    sq = s*s
    sq%=MAX
    for i in lis:
        r+=i**2
    r = (sq-r)//2
    r%=MAX
    print(r)
sol(lis)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
m=1000000007
n=int(input())
a=np.array(list(map(int,input().split())))
b=np.outer(a,a)
c=np.sum(b) //2
d=np.dot(a,a)
d=d // 2
e=c-d
print(e%m)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

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

    //ll n = 1e5; vector<ll> a(1e5,1e9);
    
    ll suma = sum(a);
    ll ans = 0;
    for(long long j = 0; j < n-1; j++){
        suma -= a[j];
        ans += (suma * a[j]);
        ans %= ll(1e9+7);
    }

    put(ans);
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
ai = list(map(int,input().split()))
sum = 0
i=0
k=1
while i<n-1:
    while k<n-i:
    sum += ai[i]*ai[i+k]
    k++
  i++
sum %= 1000000007
print(sum)

Submission status: Runtime Error

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

start_v = (sum(A) - A[0])*A[0]

ans = start_v
for i in range(2, N):
    ans += int((start_v - sum(A[1:i])*A[0])*A[i-1]/A[0])

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>
#include<string>

using namespace std;


int main()
{
	const int mod = int(pow(10.0, 9.0)) + 7;
	int N;
	cin >> N;

	long long int* A = new long long int[N+1];
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
	}

	long long int sum = 0;

	for (int i = 1; i < N; i++)
	{
		for (int j = i + 1; j <= N; j++)
		{
			int times = ((A[i] % mod) *( A[j] % mod)) % mod;
			sum += times;
			sum %= mod;
		}
	}


	cout << sum;

}

Submission status: Runtime Error

Solution code:
n = input()

max = 10**9 + 7

a_list = [int(a) % max for a in input().split(" ")]

sum = 0
for i in range(0, len(a_list)-1):
    sum += a_list[i] * sum(a_list[i+1:])
sum = sum % max
print(sum)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
def rec(num):
    if len(num) == 2:
        return num[0] * num[1]
    else:
      sum_ = num[0] * sum(num[1:])    
      return  sum_ + rec(num[1:])
print(pow(rec(num),1, mod))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.asarray(input().split()).astype(np.int)
'''
ans = 0
for i in range(N):
    pA = A[i] * A[i+1:]
    ans += pA.sum()

print(int(ans % (1e9+7)))
'''
a = np.tile(A,(N, 1))
a = a * a.T

a_diag = np.diag(a).sum()
a = ((a.sum()-a_diag)/2)
#print(a/10e9+7)
print(int(np.mod(a, 10**9+7)))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
#define p push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n" 

void solve(){
    lli n;
    cin>>n;
    vector<lli>a;
    for(lli i=0;i<n;i++){
        lli s;
        cin>>s;
        a.p(s);
    }
    lli sum=0;
    for(lli i=0;i<n-1;i++){
        for(lli j=i+1;j<n;j++){
            sum+=(a[i]*a[j]);
        }
    }
    cout<<sum%(1000000007);
}
int main(){
    fast;

    solve();
}

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())), dtype=int)
xx, yy = np.meshgrid(numbers, numbers)
times = xx * yy
eye = (np.eye(3) + 1) % 2
times_sum = (times * eye / 2).sum()
print(int(times_sum))

Submission status: Runtime Error

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

max = (10 ** 9) + 7

sum = 0
for i in range (n-1):
    for j in range (n):
        if i > j:
            continue
        if i != j:
            sum += a[i]*a[j]
#        if sum > max:
#            sum - max

if sum > max:
    ans = sum % max

print(ans)

Submission status: Runtime Error

Solution code:
#C
import numpy as np
n  = int(input())
a_ls = list(map(int, input().split()))

a_ls = (np.array([a_ls]))%(10**9+7)
a_ls2 = (np.array(a_ls).T)
tmp = np.dot(a_ls2, a_ls)%(10**9+7)
tmp = np.tril(tmp)
ans = (np.sum(tmp)%(10**9+7) - np.sum(np.diag(tmp))%(10**9+7)) % 10**9+7
ans = int(ans)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
def rec(num):
    if len(num) == 2:
        return num[0] * num[1]
    else:
      sum_ = num[0] * sum(num[1:])    
      return  sum_ + rec(num[1:])
print(pow(rec(num),1, mod))

Submission status: Runtime Error

Solution code:
def findProductSum(A,n): 
  
    product = 0
    for i in range (n): 
        for j in range ( i+1,n): 
            product = product + A[i]*A[j] 
    return product 
   
# Driver code 
if __name__=="__main__": 
  
    A=[]
    n = int(input())
    for i in range(n):
      a=int(input())
      A.append(a)
    print( findProductSum(A, n))

Submission status: Runtime Error

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

m = (10**9 + 7)
result = [(a[i]*a[j])%m for i in range(n) for j in range(n) if i < j]
print(sum(result)%m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import java.util.*;

public class Main {
    
    static Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        
        int n = Integer.parseInt(sc.nextLine()),sm = 0;
        String[] a = sc.nextLine().split(" ");
        for (int i = 0;i < a.length;i++){
            for (int j = i + 1;j < a.length ;j++){
                sm += Integer.parseInt(a[j]) * Integer.parseInt(a[i]);
            }
            
        }
        
        System.out.println(sm % 1000000007);
    }
}

Submission status: Runtime Error

Solution code:
def findProductSum(A, n): 
    array_sum = 0
    for i in range(n): 
        array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
    for i in range(n): 
    	individual_square_sum += A[i] * A[i] 
    return ((array_sum_square-individual_square_sum)/2)%1000000007

if __name__ == '__main__': 
    n = int(input())
    arr=list()
    for i in range(n):arr.append(int(input()))
    print(int(findProductSum(arr, n)))

Submission status: Runtime Error

Solution code:
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    temp=int(array_sum_square - 
            individual_square_sum) / 2
    return temp%1000000007








list=list()
n=int(input())
for i in range(n):
	l=int(input())
	list.append(l)
print(findProductSum(list,n))

Submission status: Runtime Error

Solution code:
n,m = (int(x) for x in input().split())
friendlist = [0]*n
classes = 1
for i in range(m):
    a,b = (int(x)-1 for x in input().split())
    if friendlist[a]!=0 and friendlist[b]!=0:
        continue
    elif friendlist[a]!=0:
        friendlist[b] = friendlist[a]
    elif friendlist[b]!=0:
        friendlist[a] = friendlist[b]
    else:
        friendlist[a] = classes
        friendlist[b] = classes
        classes += 1

count = [0]*classes
maxa = 0
for i in range(n):
    count[friendlist[i]] += 1
    maxa = max([count[friendlist[i]],maxa])

print(maxa)

Submission status: Runtime Error

Solution code:
n= int(input())
lst = [int(i) for i in input().split()]
lst = sorted(lst)
count = 0
d_lst = []
for i in range(len(lst)):
    for j in range(i+1,len(lst)):
    # print(i,j)
        a = lst[i] * lst[j]
        if lst[j] in d_lst:
            continue
        else:
            if lst[i] == lst[j]:
                d_lst.apend(lst[j])
                count += a
            else:
                count += a
    
if count > ( 10**9 + 7 ):
    print(count % (10**9 + 7))
else:
    print(count)

Submission status: Runtime Error

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

result = 0
for i in range(N-1):
    result+=As[i]*sum(As[i+1:])
print(result%(1*10**9+7))

Submission status: Runtime Error

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

const int mod = 1e9 + 7;

using ll = long long;

int solve(const vector<ll>& A, ll n)  {
    ll sum = A[0];
    ll res = 0;
    for(int i=1; i<n; i++) {
        res = (res + (sum * A[i]) % mod) % mod;
        sum = (sum + A[i]) % mod;
    }
    return res;
} 
int32_t main() 
{ 
    ll n;
    cin >> n;
    vector<ll> arr(n);
    for(ll& i : arr) cin >> i;
    cout << solve(arr, n) << '\n';
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

np_al = np.array(A_list)
dot = np.outer(np_al, np_al)

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

Submission status: Runtime Error

Solution code:
ut())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation = sum((B[i] * (sum(B[j] for j in range(i+1,N)) % x)) % x for i in range(N-1)) % x
print(summation)

Submission status: Runtime Error

Solution code:
n = int(input())
num = list(map(int, input().split()))
def rec(num):
    if len(num) == 2:
        return num[0] * num[1]
    sum_ = num[0] * sum(num[1:])    
    return  sum_ + rec(num[1:])
print(rec(num) % 1000000007)

Submission status: Runtime Error

Solution code:
import numpy as np
t=np.array(input().split(' '))
num=np.zeros(n)
for a in range(n):
  num[a]=int(t[a])
a=np.sum(num)**2
b=np.sum(num**2)
x=(a-b)/2
print(int(x))

Submission status: Runtime Error

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

const int mod = 1e9 + 7;

using ll = long long;

int solve(const vector<ll>& A, ll n)  {
    ll add = A[0];
    ll res = 0;
    for(int i=1; i<n; i++) {
        res = (res + (add * A[i]) % mod) % mod;
        add = (add + A[i]) % mod;
    }
    return res;
} 
int32_t main() 
{ 
    ll n;
    cin >> n;
    vector<ll> arr(n);
    for(ll& i : arr) cin >> i;
    cout << solve(arr, n) << '\n';
}

Submission status: Runtime Error

Solution code:
s = int(input())

num = input()
num = num.split()
 
for i in range(s):
    num[i] = int(num[i])

ans = []
count = 0
while count != s-1:
    print("count is " + str(count) + "s is" + str(s))
    print("now k : " + str(num[0]))
    k = num[0]
    for j in range(s - count -1):
        print(num[j+1])
        ans.append( k * num[j+1])
        print("now ans : " + str(ans))
    num.pop(0)
    count = count +1
print("end " + str(ans))

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

Submission status: Runtime Error

Solution code:
def sum_a(array):
    total = 0
    for i in range(len(array)):
        total += array[i]**2
    return(total)

n = int(input())
a = list(map(int,input().split()))
import numpy as np
b = a.copy()
c = np.array(a)
d = np.array(b)

e = np.outer(c,d)

f = np.sum(e)
g = sum_a(a)

print((int((f-g)/2)%(10**9+7)))

Submission status: Runtime Error

Solution code:
def findProductSum(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
    for i in range(0, n, 1): 
    	individual_square_sum += A[i] * A[i] 
    return ((array_sum_square-individual_square_sum)/2)%1000000007

if __name__ == '__main__': 
    n = int(input())
    arr=list()
    for i in range(n):
    	arr.append(int(input()))
    print(int(findProductSum(arr, n)))

Submission status: Runtime Error

Solution code:
sum_ = 0
temp = 0
for i in range(len(a)-1):
    temp += a[-i-1]
    sum_ += temp * a[-i-2]

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