Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

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

Constraints

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

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

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

Sample Input 1

3
1 2 3

Sample Output 1

11

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

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(n):
        if i != j:
            ans += al[i]*al[j]

print((ans//2)%mod)

Submission status: Time Limit Exceeded

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

l = len(ai)

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

ans = s % (1000000000 + 7)

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):
    for j in range(i + 1, N):
        Sum += A[i] * A[j]

print(Sum % 1000000007)

Submission status: Time Limit Exceeded

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

X=[]
for i in range(N):
  for j in range(i+1,N):
    X.append(A[i]*A[j])
x=sum(X)

MOD=1000000007
print(x%MOD)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
p=input()
p=p.split()
A=[]
for i in range(len(p)):
  A.append(int(p[i]))

X=[]
for i in range(N):
  for j in range(i+1,N):
    X.append(A[i]*A[j])
x=sum(X)

MOD=1000000007
print(x%MOD)

Submission status: Time Limit Exceeded

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

sum_of_product = 0

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

print(sum_of_product)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
n = int(input())
a = [int(x) for x in input().split()]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    for j in range(i+1,n):
        sum+=(A[i]*A[j])%J
        sum%=J
print(sum%J)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

mod = 10**9 + 7

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            d = a[i]*a[j]
            d = d%mod
            ans += d
            ans%=mod
    print(ans)

Submission status: Time Limit Exceeded

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

score=0
for j in range(n):
  i=0
  while i < j:
    score += a[i]*a[j]
    i += 1
print(score%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(b)):
    for j in range(i,len(b)):
        if i<j:
            sum += (b[i]) * (b[j])
    sum %= (10**9+7)
       
    
print(sum)

Submission status: Time Limit Exceeded

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

for i in range(len(b)):
    for j in range(i,len(b)):
        if i<j:
            sum += (b[i]) * (b[j])
    
print(sum % (10**9+7))

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    for j in range(len(a)):
        if i<j:
            sum += (a[i]%(10**9+7)) * (a[j]%(10**9+7))
    
print(sum % 1000000007)

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    for j in range(len(a)):
        if i<j:
            sum += a[i] * a[j] %1000000007
    
print(sum % 1000000007)

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    for j in range(len(a)):
        if i<j:
            sum += a[i] * a[j]
    
print(sum%1000000007)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
for i in range(num):
	num_a = num_list[i]
	temp_sum = 0
	for j in range(i+1,num):
		temp_sum += num_list[j]
    	
    
	sigma += num_a * temp_sum

sigma %= law
print(sigma)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
input_line = input().split()

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
	num_a = num_list[i]
	temp_sum = 0
	for j in range(i+1,num):
		temp_sum += num_list[j]
    	
    
	sigma += num_a * temp_sum % law

sigma %= law
print(sigma)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
input_line = input().split()

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
  for j in range(i+1,num):
    num_a = num_list[i]
    num_b = num_list[j]
    
    sigma += num_a * num_b

sigma %= law
print(sigma)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
input_line = input().split()

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
  for j in range(i+1,num):
    num_a = num_list[i]
    num_b = num_list[j]
    
    sigma += (num_a * num_b)%law

sigma %= law
print(sigma)

Submission status: Time Limit Exceeded

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

print(an)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

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

comb = np.array(list(combinations(A_list, 2)))
comb_mul = np.apply_along_axis(lambda x: x[0]*x[1], 1, comb)
total_sum = sum(comb_mul)
mod_result = total_sum % (10**9+7)

print(mod_result)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

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

comb = list(combinations(A_list, 2))
comb_mul = list(map(lambda row: row[0]*row[1], comb))
total_sum = sum(comb_mul)
mod_result = total_sum % (10**9+7)

print(mod_result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a = list(input().split())
ans = 0
mod = 1000000007
for v in itertools.combinations(a,2):
    ans += int(v[0])*int(v[1])
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
#####
# C #
#####

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

ans = 0
for i in range(len(A)-1):
    tmp1 = A[i] % (10**9 + 7)
    tmp2 = sum(A[i+1:]) % (10**9 + 7)
    ans += tmp1 * tmp2
    ans %= (10**9 + 7)
    # for j in range(1,len(A)-i
    #     # print(A[i],'A[i]',A[i+j],'A[i+j]')
    #     tmp_ai = A[i] % (10**9 + 7)
    #     tmp_aij = A[i+j] % (10**9 + 7)
    #     tmp += (tmp_ai * tmp_aij) % (10**9 + 7)
    #     # print(tmp,'tmp')
    # tmp %= (10**9 + 7)
    # ans += tmp

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(A)-1):
    tmp = 0
    for j in range(1,len(A)-i):
        # print(A[i],'A[i]',A[i+j],'A[i+j]')
        tmp_ai = A[i] % (10**9 + 7)
        tmp_aij = A[i+j] % (10**9 + 7)
        tmp += (tmp_ai * tmp_aij) % (10**9 + 7)
        # print(tmp,'tmp')
    tmp %= (10**9 + 7)
    ans += tmp

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(A)-1):
    tmp = 0
    for j in range(1,len(A)-i):
        # print(A[i],'A[i]',A[i+j],'A[i+j]')
        tmp_ai = A[i] % (10**9 + 7)
        tmp_aij = A[i+j] % (10**9 + 7)
        tmp += tmp_ai * tmp_aij
        # print(tmp,'tmp')
    tmp %= (10**9 + 7)
    ans += tmp

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(A)-1):
    tmp = 0
    for j in range(1,len(A)-i):
        # print(A[i],'A[i]',A[i+j],'A[i+j]')
        tmp_ai = A[i] % (10**9 + 7)
        tmp_aij = A[i+j] % (10**9 + 7)
        tmp += tmp_ai * tmp_aij
        # print(tmp,'tmp')
    ans += tmp

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a_lis = list(map(int,input().split()))
sum = 0
mod = 10**9+7
for a,b in itertools.combinations(a_lis,2):
    sum += (a*b)%mod

print(sum%mod)

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:])
  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):
  for j in range(i+1,n):
    ans += a[i]*a[j]
  ans %= 10**9+7
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
re = 0
re2 = 0

for i in range(n):
    re += a[i]*sum(a[i+1:])
    #for m in range(n-i-1):
        #re = a[i]*a[i+m+1]
        #re2 += re

ans = re %1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
re = 0
re2 = 0

for i in range(n):
    for m in range(n-i-1):
        re = a[i]*a[i+m+1]
        re2 += re

ans = re2 %1000000007
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):
  for j in range(i+1, n):
    ans += a[i] * a[j]
    
ans %= 10 ** 9 + 7
print(ans)

Submission status: Time Limit Exceeded

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

s = 0

for i in range(N):
    for k in range(i+1, N):
        s += a[i] * a[k]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

l = np.array([int(i) for i in input().split()],dtype = np.int64)

l2 = np.array([],dtype = np.int64)
for i in range(n):
    l2 = np.r_[l2,l * l[i]]
l2 = l2.reshape(n,n).T

l2 = np.triu(l2,1)

print(l2.sum()%mod)

Submission status: Time Limit Exceeded

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

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

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):
    for j in range(i+1, N):
        ans += A[i]*A[j]

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
re = 0
for i in range(n):
    for m in range(n-i-1):
        re += a[i]*a[i+m+1]

ans = re %1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = list(map(int,input().split()))
re = 0
for i in range(n):
    for m in range(n-i-1):
        re += a[i]*a[i+m+1]

ans = re %1000000007
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

import sys
input = sys.stdin.readline
#sys.stdout.write(str(ans))
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))


def ans():
    s = 0
    for i in range(n):
        s+=a[i]*sum(a[i+1:])
    return s%1000000007


n = inp()
a = inlt()
print(ans())

Submission status: Time Limit Exceeded

Solution code:
def ans():
    s = 0
    for i in range(n):
        s+=a[i]*sum(a[i+1:])
    return s%1000000007


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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] + list(map(int,input().split()))
ansl = []
ans = 10**9 + 7

for i in range(1,N+1):
    for j in range(1,N+1):
        if i < j:
            ansl.append((A[i])*(A[j]))

print(sum(ansl)%ans)

Submission status: Time Limit Exceeded

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

l=list(range(0,N))
x=0

for i in l:
    k=1
    while k<=N-1:
        if i+k<=N-1:
            x=x+list1[i]*list1[i+k]
            k=k+1
        else:
            k=k+1

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

print(int(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(int(ans))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
p=input()
p=p.split()
A=[]
for i in range(len(p)):
  A.append(int(p[i]))

X=[]
for i in range(N):
  for j in range(i+1,N):
    X.append(A[i]*A[j])
x=0
for i in range(len(X)):
  x+=X[i]

MOD=1000000007
print(x%MOD)

Submission status: Time Limit Exceeded

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

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

ans = ans%m

print(ans)

Submission status: Time Limit Exceeded

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

WA = [sum(A[n:])%mod for n in range(N)]

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

print(total%mod)

Submission status: Time Limit Exceeded

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

WA = [sum(A[:n+1])%mod for n in range(N)]

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

print(total%mod)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

WA = [sum(A[:n+1])%mod for n in range(N)]

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

print(total%mod)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

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

print(total%mod)

Submission status: Time Limit Exceeded

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

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]

n = int(input())
A = ip()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(sum_ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(sum_ans)

Submission status: Time Limit Exceeded

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

print(sum_ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
result = 0
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(i+1, N):
    calc = result + A[i] * A[j]
    compare = calc // mod
    result = calc if compare < 1 else calc - compare * mod
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import numpy as np
    import itertools
    readline = sys.stdin.readline

    n = int(readline())

    a = list(map(int, readline().split()))
    a_c = list(itertools.combinations(a, 2))

    a0 = np.array([a_c[i][0] for i in range(len(a_c))])
    a1 = np.array([a_c[i][1] for i in range(len(a_c))])

    ans_b = np.matmul(a0%(1e+9 + 7), a1)
    ans = ans_b % (1e+9 + 7)

    print(f"{ans:.0f}")


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
BIG = 10**9 + 7
def sumpp(n,a):
    acc = 0
    for i in range(n-1):
        acc += a[i] * sum(a[i+1:])
    return acc % BIG
input = sys.stdin.readline
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(sumpp(n,a))

Submission status: Time Limit Exceeded

Solution code:
import sys
BIG = 10**9 + 7
def sumpp(n,a):
    acc = 0
    for i in range(n-1):
        for j in range(i+1,n):
            acc += a[i] * a[j]

    return acc % BIG
input = sys.stdin.readline
if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(sumpp(n,a))

Submission status: Time Limit Exceeded

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

M = 10**9 + 7

for n in range(N):
    A[n] = A[n] % M

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

M = 10**9 + 7

for n in range(N):
    A[n] = A[n] % M

ans = 0

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

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-1):
    for n in range(i + 1, N):
        ans += A[i] * A[n]
    ans = ans % M

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-1):
    for n in range(i + 1, N):
        ans += A[i] * A[n]
        ans = ans % M

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int, input().split()))
p = 0
for n in range(N):
  for m in range(n+1, N):
    p += X[n]*X[m]
  if p >= 10**9 + 7:
     p = p % (10**9 + 7)
      
      #while p >= 10**9 + 7:
        #p -= 10**9 + 7
      
print(p)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int, input().split()))
p = 0
for n in range(N):
  for m in range(n+1, N):
    p += X[n]*X[m]
  if p >= 10**9 + 7:
    while p >= 10**9 + 7:
      p -= 10**9 + 7
      
print(p)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int, input().split()))
p = 0
for n in range(N):
  for m in range(n+1, N):
    p += X[n]*X[m]
    if p >= 10**9 + 7:
      while p >= 10**9 + 7:
        p -= 10**9 + 7
      
print(p)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
sum_sum = []
for i in range(1,N):
  sum_sum.append(sum(a[i:])%MOD)
for i in range(1,N):
  sum_n = (sum_n + (a[i-1] * sum_sum[i-1]) % MOD) % MOD
print(sum_n % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
sum_sum = []
for i in range(N):
  s = 0
  for j in range(i+1,N):
    s = (s + a[j]) % MOD
  sum_sum.append(s)
for i in range(1,N):
  sum_n = (sum_n + (a[i-1] * sum_sum[i-1]) % MOD) % MOD
print(sum_n % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
for i in range(N):
  for j in range(i+1,N):
    sum_n = (sum_n + (a[i] * a[j])%MOD)%MOD
    
print(sum_n % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
  a.append(i%MOD)
for i in range(N):
  for j in range(i+1,N):
    sum_n = sum_n + a[i] * a[j]
    
print(sum_n % MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    Sum = sum(A[i+1:N])
    E = A[i]*Sum
    ans += E
ans %= 10**9+7
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):
        E = int(A[i])*int(A[j])
        Sum += E
ans = Sum%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

arr = list(map(int,input().split()))
summ  = 0

for o in range(n):

	for i in range(o+1,n):
		
		new = arr[i] * arr[o]
		summ+=new
print(summ % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

Num = 0
Dum = 0
Gum = 0

for i in range(N-1):
    Num = i
    for j in range(Num+1):
        Dum += A[j]
    Gum += Dum * A[Num + 1]
    Dum = 0

print(Gum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

B = A[1:N]   # A1を除外

C = []

Num = 0
Dum = 0
Gum = 0

for i in range(N-1):
    Num = i
    for j in range(Num+1):
        Dum += A[j]
    C.append(Dum)
    Dum = 0

for k in range(N-1):
    Gum += B[k] * C[k]

print(Gum % 1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

i = 0
j = 1
sum = 0

while j <= (N-1):
    i = 0
    while i < j:
        sum += (int(A[i]) * int(A[j]))
        i += 1
    j += 1
mod = 10**9+7
print(sum % mod)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

length = len(a)
ans = 0
for i in range(0,length-1):
  for j in range(i+1,length):
    ans += (a[i] * a[j])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=(ans-s)//2
ans=ans%(10**9+7)



print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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