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:
def mo(v):
    return v % 1000000007


n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
s = 0
for i in range(1, n, 1):
    for j in range(i + 1, n + 1, 1):
        s += mo(a[i] * a[j])
print(mo(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
sum1 = 0

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

result = sum1%1000000007
print(result)

Submission status: Time Limit Exceeded

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

data = []

for i in range(0, len(a)-1) :
        for j in range(1, len(a)) :
                try :
                        data.append(a[i]*a[j+i] % (10**9+7))
                except :
                        continue
                        
ans = sum(data) % (10**9 + 7)

print(int(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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):
    ans = (ans+(A[i]*sum(A[i+1:])%MOD)%MOD)%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A_n = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
l = [i for i in range(1, N + 1)]

for v in itertools.permutations(l, 2):
    if v[0] < v[1]:
        ans += (A_n[v[0]-1] * A_n[v[1]-1]) % mod
        ans = ans % mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
mod = 1000000000+7

def product(N, As):
  result = 0
  for i in range(N):
    left = As[i]
    rights = As[i+1:]
    result += left * sum(rights)
  return result % mod


if __name__ == "__main__":
  N = list(map(int, input().split()))
  As = list(map(int, input().split()))
  print(product(N[0], As))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
a = [num % MOD if num >= MOD else num for num in a]

ans = 0
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		acc = a[i] * a[j]
		ans += acc % MOD if acc >= MOD else acc
		ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

A_2=list(itertools.combinations(A,2))

A_3=[]

for i in A_2:
    x=(i[0]*i[1])%1000000007
    A_3.append(x)

S=sum(A_3)
    
print(S%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
input1 = input()
input1 = input1.split()
A = []
sum = 0
for i in input1:
    A.append(int(i))
for i in range(N):
    for j in range(i+1,N):
        sum = sum + A[i]*A[j]
print(sum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
#pragma GCC optimize("Ofast")

a=int(input())

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

sum=0
mod = pow(10,9)+7

for i in range(a-1):
  for j in range(i+1,a):
    sum=pow(sum+d[i]*d[j],1,mod)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import itertools
N = int(input())
L = input().split()
LS = [int(i) for i in L]
count = 0
itr = list(itertools.combinations(LS, 2))
data = list(map(lambda x: (x[0] * x[1]) % 1000000007, itr))
ans = sum(data) % 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy
N = int(input())
Alist = numpy.array(list(map(int,input().split())))
MOD = 1000000007
ans = 0

for i in range(N):
    ans += sum(Alist[i] * Alist[i+1:])
    if ans > MOD:
        ans = ans % MOD

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(int(x) for x in input().split())
b = []
for i in range(1,n):
  b.append(sum(a[i:]))

MOD = 1000000007

ans = 0

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

print(ans%MOD)

Submission status: Time Limit Exceeded

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

    for i in range(N):
        for j in range(1+i, N):
            if i == j:
                continue
            else:
                ans += A[i] * A[j]
    print(ans % 1000000007)
main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
A = list(map(int, input().split()))

combi = itertools.combinations(list(range(n)),2)

ans = 0

for i in combi:
  ans += (A[i[0]] * A[i[1]])
  
print(ans % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
num_list = list(map(int, input().split()))
lists = [i for i in num_list if i != 0]

mod = (10**9)+7

sum = 0
for i in range(len(lists)-1):
    for j in range(i+1, len(lists), 1):
        if lists[i] == 0 or lists[j] == 0:
            continue
        else:
            tmp = (lists[i]*lists[j])%mod
            sum += tmp
ans = sum%mod
print(ans)

Submission status: Time Limit Exceeded

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


mod=1000000007
cnt=1
ans=0

def getMod(factor1,factor2):
    return (ans+factor1*factor2)%mod


for getA in A:
    for i in range(cnt,N):
        ans=getMod(getA,A[i])
    cnt+=1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = [i % (10**9 + 7) for i in list(map(int, input().split()))]

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

Submission status: Time Limit Exceeded

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

total = 0

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

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

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-1):
    for j in range(n-1-i):
        if a[i] >= 1000000007:
            while a[i] >= 1000000007:
                a[i] = a[i] - 1000000007
            hoge = a[i] * a[i+1+j]
        elif a[i+1+j] >= 1000000007:
            while a[i+1+j] >= 1000000007:
                a[i+1+j] = a[i+1+j] - 1000000007
            hoge = a[i]*a[i+1+j]
        else:
            hoge = a[i] * a[i+1+j] % 1000000007
        while hoge >= 1000000007:
            hoge = hoge - 1000000007
        ans = ans + hoge

ans = ans % 1000000007
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
n_list = [int(i) for i in input().split()]
ans = 0
mod = 10 ** 9 + 7
num_list = [n % mod for n in n_list]
a_list = []

while len(num_list) > 1:
    x = num_list[0]
    num_list.remove(x)
    a_list.append((x * (sum(num_list) % mod)) % mod)

ans = sum(a_list) % mod

print (ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy
N = int(input())
Alist = numpy.array(list(map(int,input().split())))
MOD = 1000000007
ans = 0

for i in range(N):
    ans += sum(Alist[i] * Alist[i+1:])
    ans = ans % MOD

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    for j in range(i, len(a)):
        if i == j:
            continue
        else:
            res += a[i]*a[j]
            res = res % (10**9+7)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
alist = list(map(int, input().split()))
result = 0
nmod = 10 ** 9 + 7
    
for i in itertools.combinations(alist, 2):
  result = (result + i[0] * i[1]) % nmod
  
print(result)

Submission status: Time Limit Exceeded

Solution code:
from numba import njit

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

@njit
def solution(A,N):
    mod = (10**9)+7
    res = 0
    for i in range(N-1):
        for j in range(i+1,N):
           res += ((A[i] % mod) * (A[j] % mod)) % mod
    return res
  
mod = (10**9)+7
res = solution(A,N)
print(res % mod)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
num = list(map(int,input().split()))
ans = 0

for i in range(s-1):
    ni = num[i]
    for j in range(s - i -1):
        nj = num[i+j+1]
        ans =  ans + (ni * nj)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
num_list = list(map(int, input().split()))
lists = [i for i in num_list if i != 0]

mod = (10**9)+7
mod_list = []
sum = 0
for i in range(len(num_list)-1):
    for j in range(i+1, len(num_list), 1):
        if num_list[i] == 0 or num_list[j] == 0:
            continue
        else:
            tmp = (num_list[i]*num_list[j])%mod
            sum += tmp
ans = sum%mod
print(ans)

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

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

sum = 0
mod = 1000000000+7
for i in range(n):
    if a[i] >= mod:
        a[i] = a[i] % mod
for i in range(n-1):
    #if a[i] >= mod:
        #a[i] = a[i] % mod
    for j in range(i+1, n):
        #if a[j] >= mod:
            #a[j] = a[j] % mod
        sum = sum + a[i] * a[j]
        #print(sum)
        if sum >= mod:
            #print('no')
            sum = sum % mod
            #print(sum)
            #print('o')
print(sum)

Submission status: Time Limit Exceeded

Solution code:
m = (10 ** 9) + 7
n = int(input())
arr = list(map(int, input().split()))
sum = 0
import itertools
for j in itertools.combinations(arr, 2):
  sum += (j[0]%m * j[1]%m)
print(sum % m)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
AA=A[0:len(A)-1]
BB=[]
end=len(A)
for i in range(1,end):
    BB.append(sum(A[i:end]))
ANS=sum([x * y for (x, y) in zip(AA, BB)])
print(ANS%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_list.insert(0,0)
sum = 0
for i in range(1, N):
    for j in range(i + 1, N + 1):
        sum += (A_list[i] * A_list[j])
        sum = sum % 1000000007
print(sum)

Submission status: Time Limit Exceeded

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

x = 0
for i in range(len(l) - 1):
    for t in range(i + 1, len(l)):
        x += l[i]*l[t]

y = x % (10**9 + 7)
print(y)

Submission status: Time Limit Exceeded

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

mod=10**9+7
sum_all=[]
for i in range(N-1):
    for j in range(i+1,N):
        A[i]=A[i]%mod
        A[j]=A[j]%mod
        sum_all.append((A[i])*(A[j]))

sum=0
for n in sum_all:
    sum+=n
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import itertools

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

C = np.array(list(itertools.combinations(A,2)))
# print(C[0][0])
# print(len(C))

product = 0
product_sum = 0
for i in range(len(C)):
    product = ((C[i][0] % (1E+9+7)) * (C[i][1] % (1E+9+7)))
    product_sum = product_sum + product
    product_sum = product_sum % (1E+9+7)

answer = product_sum % (1E+9+7)
print(int(answer))

Submission status: Time Limit Exceeded

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

    m = 10 ** 9 + 7
    ans = 0
    a = [i % m for i in a]
    for i in range(n):
        for j in range(i + 1, n):
            ans += a[i] * a[j]
            if ans >= m:
                ans = ans % m
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#pragma GCC optimize("Ofast")

a=int(input())

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

sum=0
b=0
mod = pow(10,9)+7

for i in range(a-1):
  for j in range(i+1,a):
    sum=sum+d[i]*d[j]
    b=pow(sum,1,mod)

print(b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
mod_const = 1000000007
ans = 0
for i, j in list(itertools.combinations(a, 2)):
  ans += (i * j)
  if (ans >= mod_const):
    ans %= mod_const

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
k = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
S = 0
for c in itertools.combinations(L, 2):
  S += (c[0] * c[1]) % k
print(S % k)

Submission status: Time Limit Exceeded

Solution code:
mod = 1000000000+7

def product(N, As):
  result = 0
  for i in range(N):
    left = As[i]
    rights = As[i+1:]
    result += sum(list(map(lambda x: x*left, rights)))
  return result % mod


if __name__ == "__main__":
  N = list(map(int, input().split()))
  As = list(map(int, input().split()))
  print(product(N[0], As))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = list(map(int, input().strip().split()))
S = 0

for i in range(N):
    for j in range(N-1-i):
        S += An[i]*An[N-1-j]%1000000007
    S %= 1000000007

print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum = 0

for pair in itertools.combinations(A, 2):
    # print(pair)
    sum += (pair[0] * pair[1]) % (10**9+7)
    if(sum >= 10**9+7):
        sum = sum % (10**9+7)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# from pprint import pprint
# import math
# import collections

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

MOD = 10 ** 9 + 7

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

        # print(i, j, _)

print(sum % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
sum = 0
# temp1 = 0
# temp2 = 0
MOD = 1000000007
# for i in range(0, N-1):
#     A[i] = A[i] % MOD
#print(A)
for i in range(0, N-1):
    A[i] = A[i] % MOD
    for j in range(i+1, N):
        #print(i, j)
        # temp1 = 0
        # temp2 = 0
        temp3 = 0
        # temp1 = A[i] % MOD
        # temp2 = A[j] % MOD
        # temp3 = temp1 * temp2
        temp3 = (A[i] * A[j]) % MOD
        sum = (sum + temp3) % MOD
#sum = sum % MOD
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
n = 10 ** 9 + 7
A_n = [int(i) % n for i in input().split()]
b_n = []
for i in range(N-1):
    for j in range(i+1, N, 1):
        b_n.append((A_n[i] * A_n[j]) % n)
print(sum(b_n)%n)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

data = []
by2 = []


for i in range(0, len(a)-1) :
        for j in range(1, len(a)) :
                try :
                        data.append(a[i]*a[j+i] % (10**9+7))
                except :
                        continue
                        
ans = sum(data) % (10**9 + 7)

print(int(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
a = [input().split() for l in range(2)]
count = 0
N = int(a[0][0])
b = [int(x) for x in a[1]]

for i in range(N):
    for j in range(i):
        if i != j:
            count = (b[i]*b[j]) % 1000000007 + count
count = count % 1000000007
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
MOD = 10**9 + 7
n=int(input())
a=list(map(int,input().split()))
sum=0
for x,y in combinations(a,2):
   sum+=x*y%MOD
   sum=sum%MOD
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def product(list):
    p = 1
    for i in list:
        p *= i
    return p


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
P = 0
A_l = [num% (10**9+7) for num in A]

for i in range(N):
  for j in range(i+1,N):
    p = A_l[i]*A_l[j]
    P += p
    
sum = P%(10**9+7)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int, input().split()))
mod_a = [i%(10**9 + 7) for i in a]
cop = copy.deepcopy(mod_a)
res = 0
for i in cop:
  b = i
  #print(b)
  #cop[i]
  #print(mod_a)
  if len(mod_a)!=1:
  	mod_a.remove(i)
  	mod_b = [j*b%(10**9 + 7) for j in mod_a]
  	res += (sum(mod_b))%(10**9 + 7)
  	#print(res)
print(res%(10**9 + 7))

Submission status: Time Limit Exceeded

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

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

result = sum % mod
print(result)

Submission status: Time Limit Exceeded

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

for team in itertools.combinations(A, 2):
    ans=ans+((team[0]*team[1])%(10**9+7))
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

while len(num_list) > 1:
    x = num_list[0]
    num_list.remove(x)
    ans += (x * (sum(num_list) % mod)) % mod
    ans = ans % mod

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

print (ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input()) 
l=list(map(int,input().split())) 
s=0 
i=0 
j=i+1
while(i<j): 
  s=s+(l[i]*l[j])


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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

    m = 10 ** 9 + 7
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += a[i] % m * a[j] % m
            # seki = a[i] * a[j]
            # ans += seki % m
            if ans >= m:
                ans = ans % m
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from collections import defaultdict, deque


def A(d, t, s):
  if t * s >= d:
    return 'Yes'
  return 'No'


def B(s, t):
  len_t = len(t)
  len_s = len(s)

  def _get_to_change(a, b):
    assert len(a) == len(b)
    to_change = 0
    for i in range(len(a)):
      if a[i] != b[i]:
        to_change += 1
    return to_change

  min_to_change = 1001
  for i in range(len_s - len_t + 1):
    to_change = _get_to_change(s[i:i + len_t], t)
    if to_change < min_to_change:
      min_to_change = to_change
  return min_to_change


def _bits(x):
  return "{0:b}".format(x)


def qmul(x, y, mod):
  ret = 0
  # print(_bits(x), _bits(y), _bits(ret), x, y, ret)
  while y:
    if y & 1:
      ret = (ret + x) % mod
    x = x * 2 % mod
    y >>= 1
    # print(_bits(x), _bits(y), _bits(ret), x, y, ret)
  return ret


def C(n, a):
  ans1 = 0
  ans2 = 0
  for i in range(n):
    for j in range(i + 1, n):
      # ans1 += (a[i] * a[j]) % (10**9 + 7)
      # ans1 %= (10**9 + 7)
      ans2 += qmul(a[i], a[j], (10**9 + 7))
      ans2 %= (10**9 + 7)
      # print(i, j, a[i], a[j], ans1, ans2, _bits(a[i]), _bits(a[j]), _bits(ans1),
      #       _bits(ans2))
  return ans2


def D(n):
  pass


def main():
  # d, t, s = map(int, input().split())
  # print(A(d, t, s))
  # s = input()
  # t = input()
  # print(B(s, t))
  n = int(input())
  a = list(map(int, input().split()))
  print(C(n, a))


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum = 0

for pair in itertools.combinations(A, 2):
    # print(pair)
    sum += (pair[0] * pair[1]) % (10**9+7)

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

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

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

sum = 0
mod = 1000000000+7
for i in range(n-1):
    if a[i] >= mod:
        a[i] = a[i] % mod
    for j in range(i+1, n):
        if a[j] >= mod:
            a[j] = a[j] % mod
        sum = sum + a[i] * a[j]
        #print(sum)
        if sum >= mod:
            #print('no')
            sum = sum % mod
            #print(sum)
            #print('o')
print(sum)

Submission status: Time Limit Exceeded

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

import itertools

ans = 0
i = 0
j = 0
for i,j in itertools.product(range(0,N), range(0,N)):
  if i < j:
    ans = ans + A[i]*A[j] % (10**9+7)
    ans = ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

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


total = 0
for i in range(n-1):
    for j in a[i+1:]:
        t = a[i]%(10**9+7)
        k = j%(10**9+7)
        total += (t*k)
        total = total%(10**9+7)

print(total)

Submission status: Time Limit Exceeded

Solution code:
a = [input().split() for l in range(2)]
count = 0
N = int(a[0][0])
 
for i in range(N):
    for j in range(i):
        if i != j:
            count = (int(a[1][i])*int(a[1][j])) % 1000000007 + count
count = count % 1000000007
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
n = len(A)
z = 10 ** 9 + 7
ans = 0
x = 0
y = 0
for i in range(n - 1):
    B = A[i + 1:n]
    x = sum(B) % z
    y = (A[i] * x) % z
    ans = (ans + y) % z

print(ans)

Submission status: Time Limit Exceeded

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

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

d = 1000000000 + 7

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

Submission status: Time Limit Exceeded

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

outer_sum = 0
for i in range(N-1):
    j = i + 1
    inner_sum = 0
    for k in range(j,N):
        inner_sum += A[i] * A[k]
    outer_sum += inner_sum

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
N = int(input())
number_list = list(map(int, input().split()))
number_list_2 = [number%MOD for number in number_list]
sum_number = 0

for i, number in enumerate(number_list_2):
	sum_number += ((number)*(sum(number_list_2[i+1:])%MOD))% MOD
	sum_number %= MOD
print(sum_number)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

saisyo = input()
X = NextInts()
p = itertools.combinations(X, 2)
ANSWER = 0
for i in p:
	answer = int(i[0])*int(i[1])
	ANSWER+=answer
print(ANSWER%(10**9+7))

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum_list =[p[i]*p[t] for i in range(a) for t in range(a) if i<=t and not i ==t]
num = sum(sum_list)%mod
print(num)

Submission status: Time Limit Exceeded

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


mod=1000000007
cnt=1
ans=0

def getMod(factor1,factor2):
    return (ans+factor1*factor2)%mod


for getA in A:
    for i in range(cnt,len(A)):
        ans=getMod(getA,A[i])
    cnt+=1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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]
            ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = [i % (10**9 + 7) for i in list(map(int, input().split(' ')))]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N - 1):
    a = A[i]
    temp_A = A[i + 1:N]
    temp_A = list(map(lambda x: x * a, temp_A))
    num_sum += sum(temp_A)


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

print(num_sum)

Submission status: Time Limit Exceeded

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

    M = 10 ** 9 + 7

    combinations = [(i, j) for i in range(N-1) for j in range(i+1, N)]

    print(sum([A[i] * A[j] for (i, j) in combinations]) % M)


main()

Submission status: Time Limit Exceeded

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