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())
A=input().split()
x=[]
 
for i in range(N):
    j=i+1
    while j <= N-1:
        x.append(int(A[i])*int(A[j]))
        j=j+1
ans=(sum(x))%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def sekiwa(x):
    n = len(x)
    result = 0
    MOD = 1000000007
    for i in range(n-1):
        for j in range(i+1, n):
            N = nums[i]*nums[j] % MOD
            result += N
            result = result % MOD
    return result

n = int(input())
nums = list(map(int, input().split()))
print(sekiwa(nums))

Submission status: Time Limit Exceeded

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

sum = 0
k = 7 + 10**9


for i in range(0,n):
    a[i] = a[i] % k

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

sum = sum % k
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
from heapq import heapify, heappop, heappush, heappushpop

class PriorityQueue:
    def __init__(self, heap):
        '''
        heap ... list
        '''
        self.heap = heap
        heapify(self.heap)

    def push(self, item):
        heappush(self.heap, item)

    def pop(self):
        return heappop(self.heap)

    def pushpop(self, item):
        return heappushpop(self.heap, item)

    def __call__(self):
        return self.heap


heap = []  # ヒープといっても順序を工夫したただのリスト

q = PriorityQueue(heap) #ここでインスタンスを作ってます
n = int(input())
l = list(map(int, input().split()))
mod = 1000000007
for a,b in itertools.combinations(l, 2):
    q.push(((a % mod) * (b % mod)) % mod)
print(sum(heap) % mod)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
import sys
import math
import numpy as np
import copy

n = input()
a = [int(p) for p in input().split(' ')]

#行列生成
aa = []
ab = []
for i in range(len(a)):
    p = copy.copy(a)
    p[i] = 0
    aa.append(p)
    ab.append([a[i]])

a1 = np.array(aa)
a2 = np.array(ab)

#print(a1 * a2)
print((np.sum(a1 * a2) // 2) % (1000000000 + 7))

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
        if ans >= 1000000007:
            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)

result = 0
for i in range(n):
    x = a[i]
    if abs(x-m) < x:
        x -= m
    y = 0
    for j in range(i+1, n):
        y = (y + a[j]) % m
    result = (result + (x*y)) % m

if(result < 0):
    result += m
print(result)

Submission status: Time Limit Exceeded

Solution code:
c = int(input())
a = list(map(int,input().split()))
b = [] + a
n = 0
result = 0
while n < c:
    b.pop(0)
    result = (result + sum(b) * a[n]) % 1000000007
    n = n + 1
print(int(result%1000000007))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

n=int(input())
nums=[int(i) for i in input().split()]

# tar = it.combinations(nums, 2)

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
numbers = list(map(int, input().split()))
numbers = [i % 1000000007 for i in numbers]

sum = 0
for i in range(n):
    for j in range(i + 1, n):
        sum += numbers[i] * numbers[j]
        sum %= (1000000000 + 7)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import deque

N = int(input())
A = list(map(int, input().split()))
d = deque(A)
ans = 0
MOD = 10**9 + 7
while len(d) > 0:
  tmp = d.popleft()
  for i in d:
    ans = (ans + i*tmp) % MOD

print(ans)

Submission status: Time Limit Exceeded

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

defmod = 10**9+7
for i in range(N-1):
  l[i] = l[i] % defmod

sum = 0
for i in range(N-1):
  for j in range(N-i-1):
    j += i+1
    p = l[i] * l[j]
    if p >= defmod:
      p = p % defmod
    sum += p
    sum = sum % defmod    
print(sum % defmod)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

sum=0
mod = 1000000007

def permod(x):
  return x%mod
B = list(map(permod,A))

for i in range(1,N+1):
    for j in range(1,N+1):
        if i < j:
            sum += B[i-1]*B[j-1]
            sum = sum %mod
print(sum)

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 = []
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		acc = a[i] * a[j]
		ans.append(acc % MOD if acc >= MOD else acc)
print(sum(ans) % MOD)

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
len_A = len(A_list)
for i in range(len_A):
	for j in range(i + 1, len_A):
		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()))
ans=0
for i in range(N-1):
    temp=0
    for j in range(i+1,N):
        temp+=A[j]
    ans+=A[i]*(temp%(10**9+7))
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for ai in a:
    d[ai] += 1

d2 = [(k, v) for k, v in d.items()]
dlen = len(d2)

s = 0
for i in range(dlen):
    k = d2[i][0]
    v = d2[i][1]
    if v >= 2:
        s = (s + k * k * (v * (v-1) // 2) % 1000000007)
    for j in range(i, dlen):
        k2 = d2[j][0]
        v2 = d2[j][1]
        if k != k2:
            s = (s + k * k2 * v * v2) % 1000000007
print(s)

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]
    P += p
    if P >= (10**9+7):
      P %= (10**9+7)
    
sum = P%(10**9+7)
print(sum)

Submission status: Time Limit Exceeded

Solution code:

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

sum = 0
A.sort(reverse=False)

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

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

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):
    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())
array = list(map(int,input().split()))
pro = [ array[i]*sum(array[i+1:N]) for i in range(N-1) ]
print(sum(pro)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i,j in itertools.combinations(a,2):
    cnt += i*j
print(cnt % (10**9 + 7))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
lst = list(map(int,input().split()))
newlst = list(combinations(lst,2))

sumlst = []
for a, b in newlst:
    a = a % 1000000007
    b = b % 1000000007
    x = a * b % 1000000007
    sumlst.append(x)

answer = sum(sumlst) % 1000000007
print(answer)

Submission status: Time Limit Exceeded

Solution code:
_N = int(input())
_list = list(map(int, input().split()))

_sumList = []

for i in range(_N):
  for l in range (_N):
    if i < l:
      _sumList.append(_list[i] * _list[l])

_answer = sum(_sumList) % (10**9+7)
print(int(_answer))

Submission status: Time Limit Exceeded

Solution code:

def main():
    from sys import stdin
    import numpy as np
    readline = stdin.readline

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

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

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

main()

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
nums = [int(n) for n in input().split()]
result = 0
for n in range(num):
    result += nums[n] * sum(nums[n+1:])

result = result % 1000000007

print(result)

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(i+1, n):
        sum = sum + (num_list[i] * num_list[j]) % 1000000007
        sum = sum % 1000000007


print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
mod = 10**9+7
a = [i%mod for i in map(int, input().split())]

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
n = int(input())
num_list = list(map(int, input().split()))
sum = 0
 
for i in itertools.combinations(num_list, 2):
    x = i[0] * i[1]
    if x > 10**9 + 7 :
        x = x % (10**9 + 7)
        sum += x
    else:
        sum += x
        
    if sum > 10**9 + 7:
        sum %= 10**9 + 7

print(sum)

Submission status: Time Limit Exceeded

Solution code:
a=[input() for i in range(2)]
a1=int(a[0])
a2=[int(i) for i in a[1].split()]

n=0

for i in range(a1-1):
	#print("i=",i)
	for j in range(1,a1-i):
		n+=a2[i]*a2[i+j]
		#print(i,j,n)

print(n%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from heapq import heapify, heappop, heappush, heappushpop

class PriorityQueue:
    def __init__(self, heap):
        '''
        heap ... list
        '''
        self.heap = heap
        heapify(self.heap)

    def push(self, item):
        heappush(self.heap, item)

    def pop(self):
        return heappop(self.heap)

    def pushpop(self, item):
        return heappushpop(self.heap, item)

    def __call__(self):
        return self.heap


heap = []  # ヒープといっても順序を工夫したただのリスト

q = PriorityQueue(heap) #ここでインスタンスを作ってます
n = int(input())
l = tuple(map(int, input().split()))
total = 0
mod = 1000000007
L = itertools.combinations(l, 2)
for a,b in L:
    num = ((a % mod) * (b % mod)) % mod
    q.push(num)
print(sum(heap) % mod)

Submission status: Time Limit Exceeded

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

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
len_A = len(A_list)
for i in range(len_A):
	for j in range(i + 1, len_A):
		sum +=  A_list[i] * A_list[j]
print(sum % (10**9 + 7))

Submission status: Time Limit Exceeded

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

sum = 0
k = 10**9
k += 7

for i in range(0,n):
    a[i] = a[i] % k

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
a=(map(int,input().split()))
ans=0
for a,b in itertools.combinations(a,2):
    ans+=(a*b)%(10**9+7)
    ans%=(10**9+7)
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]
    
print(ans%((10**9)+7))

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]
    answer %= mod
print(int(answer))

Submission status: Time Limit Exceeded

Solution code:
def main():

    from builtins import input, int, map

    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)

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

main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
sum = 0
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:
from itertools import combinations
n=int(input())
a=[int(_) for _ in input().split()]
l=[]
for i in range(n):
    for j in range(i+1,n):
        l.append(a[i]*a[j])    
print(sum(l)%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

number = 0
MOD = 1000000007

for i in range(N-1):
    for j in range(i+1, N):
#        print(A[i], A[j])
        number += A[i]*A[j]


if number > MOD:
    print(number%MOD)
else:
    print(number)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
total = 0

for i in itertools.combinations(range(N), 2):
    total += A[i[0]]*A[i[1]]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort(reverse=True)
M = 10**9 + 7
while True:
    fast = a.pop(0)
    for i in range(len(a)):
        ans += (fast * a[i])% M
    if len(a) == 1:
        break
print(ans % M)

Submission status: Time Limit Exceeded

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

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%mod
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum=0
mod = 1000000007

def permod(x):
  return x%mod
B = list(map(permod,A))

for v in itertools.combinations(B, 2):
    sum +=v[0]*v[1]
    sum = sum %mod
print(sum)

Submission status: Time Limit Exceeded

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

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) % mod_const

print(ans%mod_const)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

saisyo = input()
X = NextInts()

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
list_1 = []
list_1 = input().split()
list_2 = []
count = 0
for i in range(n):
    list_2.append(int(list_1[i]))

for i in range(n-1):
    for j in range(n-1-i):
        count += list_2[i]*list_2[i+1+j]
        
print(np.mod(count,10**9 + 7))

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]

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

Submission status: Time Limit Exceeded

Solution code:
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(input())
def m_in(type_): return map(type_, input().split())
def r_in(n, type_): return [type_(input()) for _ in range(n)]
ans = 0
const = 1000000007

n = i_in()
a = l_in(int)
hn = n/2
ts = sum(a)

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

print(ans%const)

Submission status: Time Limit Exceeded

Solution code:
input()
n = list(map(int, input().split(' ')))
s = 0
for i, j in enumerate(n):
    for k in range(i+1, len(n)):
        if i < k:
            s = s + (n[i]*n[k])
            #print(n[i], n[k])
print(s% ((10**9)+7))

# for i in range(len(n)):
#     for j in range(len(n)):
#         if i < j:
#             s = s + (n[i]*n[j])
# print(s% ((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
B = list(map(int, input().split()))
A = [x % (10**9 + 7) for x in B] 

x = 0
for i in range(n):
  for j in range(n):
    if j > i:
      x += A[i]*A[j]
print(x % (10**9 +7))

Submission status: Time Limit Exceeded

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(len(a)):
    for j in range(i+1, len(a)):
        alist.append((a[i] * a[j]) % dx)

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

ans %= dx
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
S = 0
for c in itertools.combinations(L, 2):
  S += (c[0] * c[1]) % (10 ** 9+7)
print(S % (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:]:
        total += (a[i]*j)
        total = total%(10**9+7)

print(total)

Submission status: Time Limit Exceeded

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

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 += i[0] * i[1]
  
s, t = divmod(result,nmod)
print(t)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007


ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod_n = 10**9+7

cum_A = [0]
for i in range(n-1):
  cum_A.append(cum_A[i]+A[::-1][i])
  
ans = 0
for i in range(n-1):
  ans += A[i]*cum_A[::-1][i]%mod_n
  
print(ans%mod_n)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a_list = list(map(int, input().split()))
max = 0

for a in itertools.combinations(a_list, 2):
    b, c = a
    max += b * c

print(max % 1000000007)

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]
print(sum(sum_list)%mod)

Submission status: Time Limit Exceeded

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

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])%1000000007
print(sum%1000000007)

Submission status: Time Limit Exceeded

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

calcs = []
for i in range(N):
    a = nums[i]
    for j in range(i+1, N):
        calcs.append(a * nums[j])

print(sum(calcs) % (1000000000+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

n=int(input())
nums=[int(i) for i in input().split()]

tar = it.combinations(nums, 2)

res = 0
for e in tar:
    res+=e[0]*e[1]

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

Submission status: Time Limit Exceeded

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

print(b)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

MOD = 1000000007
ans = 0
tmp = 0

for t in combinations(A,2):
    tmp += (t[0]*t[1])%MOD

print(tmp%MOD)

Submission status: Time Limit Exceeded

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

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

print(s%(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()))

d = 1000000000 + 7

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

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(N-i-1):
        S+=A[i]*A[i+k+1]

ans=S%1000000007

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
nums = list(map(int,input().split()))
sum = 0

for v in itertools.combinations(nums,2):
  sum += v[0]*v[1]

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

Submission status: Time Limit Exceeded

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

a=int(input())

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


w=[]

for i in range(a-1):
  for j in range(i+1,a):
    w.append(d[i]*d[j])

sum=sum(w)
mod = pow(10,9)+7
print(pow(sum,1,mod))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import itertools
def main():
    number = int(input())
    num_list = list(map(int, stdin.readline().split()))
    comb = list(itertools.combinations(num_list, 2))
    total = sum([c1*c2 for c1, c2 in comb])
    print(total % (10**9 + 7))
if __name__ == '__main__':
    main()

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)
    y = (A[i] * x) % z
    ans = (ans + y) % z

print(ans)

Submission status: Time Limit Exceeded

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


mod=1000000007
ans=0
cnt=1

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
size = int(input())
listOfNums = list(map(int,input().split(' ')))
arrayOfCalc = []

for i in range(0, len(listOfNums)-1):
  for k in range(1,len(listOfNums) - i):
    arrayOfCalc.append(listOfNums[i] * listOfNums[i + k])

print(sum(arrayOfCalc)%1000000007)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math

wk = 0

n = int(stdin.readline().rstrip())
listA=list(map(int,input().split()))
for i in range(0, len(listA)):
  for k in range(i+1, len(listA)):
    wk = wk + (listA[i] * listA[k])

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

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())
n = 10 ** 9 + 7
A_n = [int(i) % n for i in input().split()]
res = 0
for i in range(N-1):
    for j in range(i+1, N, 1):
        res += (A_n[i] * A_n[j]) % n
print(res%n)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())


num = input().split()
num = tuple(map(int, num))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
result = 0
i = 0
for x in A[:N]:
  for y in A[i+1:]:
    result += x * y
  i += 1

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

Submission status: Time Limit Exceeded

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

import itertools

total = 0
"""
for pair in itertools.combinations(A, 2):
  total += pair[0]%mod * pair[1]%mod
  """
pairs = [pair[0]%mod*pair[1]%mod for pair in itertools.combinations(A, 2)]
total = sum(pairs)

print(total % mod)

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))

x=0

for i in A_2:
    x=x+i[0]*i[1]
         
print(x%1000000007)

Submission status: Time Limit Exceeded

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