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:
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] * C[i][1]
    product_sum = product_sum + product

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

num = int(input())
total = 0
str = input().split(" ")
count = 0
table2 = list(str)
for i in table2:
    count += 1
    for j in range(count,num):
            total += int(i) * int(table2[j])
print(total % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
sums = [sum(nums[i:]) for i in range(1, len(nums))]
for i, ni in enumerate(nums[:-1]):
    res += ni*sums[i]
    res %= 10**9 + 7
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7


def main():
    ans = 0
    p = []
    for i in range(n):
        for j in range(i + 1, n):
            ans += (a[i] * a[j])% mod
            ans %= mod
            p.append((i, j))
    return ans


n, *a = map(int, read().split())
a = main()
print(a)

Submission status: Time Limit Exceeded

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

def add(a, b):
    return (a + b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
import itertools
ans = 0
c = itertools.combinations(a, 2)
for v in c:
    ans = add(ans,mul(v[0],v[1]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


A = itertools.combinations(a,2)

total = 0
for i,j in A:
    total += (i*j)
    total = total%MOD
print(total)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
A_list = tuple(map(int, input().split(' ')))

# print(N)
# print(A_list)

ret = 0
# 重複なしの組み合わせごとに積を出し、その和
for comb in combinations(A_list, 2):
  # print(comb)
  ret += comb[0] * comb[1]
  if ret > 1000000007:
    ret = ret % 1000000007
  
print(ret % 1000000007)

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:
    x = a * b % 1000000007
    sumlst.append(x)

modlst = sum(sumlst)
answer = modlst % 1000000007

print(answer)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
#ABC177  C
import itertools
import numpy as np
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007

sum = 0
l = list(itertools.combinations(a, 2))
l_np = np.array(l)
tmp = l_np.prod(axis=1)
#print(tmp)
ans = tmp.sum() % mod
print(ans)

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]))
    i += 1
print(Ans % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N= int(input())
ls= 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+=ls[i]*ls[j]%mod
        ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

print(res%m)

Submission status: Time Limit Exceeded

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		ans.append((a[i] * a[j]) % MOD)
print(sum(ans) % MOD)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from heapq import heappush, heappop
from random import randint
from time import time

class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue
    #...
queue = PriorityQueue()
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
    queue.push(num)
while len(queue) > 0:
    total += queue.pop()
print(total % mod)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

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):
    for j in range(i+1, n):
        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()))
P = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

combo = list(combinations(s, 2))
ans = 0
for comb in combo:
    ans += comb[0] * comb[1]

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = 10**9+7
z = list(map(int,input().split() ))
_sum = 0
y = len(z)
for i in range(y-1):
    _sum += (z[i]*sum(z[i+1:y]))
        #print("_sum:"+str(_sum))
print(_sum%t)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_str = input().split()
sum = 0
for i in range(N):
  for j in range(N-i-1):
    sum += int(a_str[i]) * int(a_str[i+j+1])
print(sum%(pow(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:
import sys
from collections import defaultdict

input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

D = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        v = A[i] * A[j] % MOD
        D[v] += 1
# print(D)

ans = 0
for key, item in D.items():
    ans += key * item
    # ans = (ans + (key * item)) % MOD
ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
an_np = np.array(an)
summary = 0
for i in range(0, n-1):
    summary = (summary + sum(np.multiply(an_np[i], an_np[i+1: n]) % m)) % m    
print(summary)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))

Ax = np.array([A for _ in range(N)])
Ay = Ax.transpose()
ans_map = Ax*Ay

for i in range(N):
    ans_map[i][i:] = 0
    
mod = 10**9+7
print(np.sum(ans_map) % mod)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

s = 0
for a in range(len(A)):
    for b in range(a+1, len(A)):
        s += A[a] * A[b]
c = 10 ** 9 + 7
print(s % c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

_sum = 0
_answer = 0

for i in range(_N):
  for l in range (_N):
    if i < l:
      _sum += _list[i] * _list[l]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
p = list(map(int,input().split()))
mod = 10**9 + 7
t = 1
sum_list = []
for i in range(a):
    for t in range(a):
        if i <= t and not i ==t:
            w = p[i]*p[t]
            sum_list.append(w)

print(sum(sum_list)%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
dd=1000000007
ss = list(map(int, input().strip().split()))
total=0

for i in range(N):
    total=total+ss[i]*sum(ss[i+1:])%(dd)

total = total %(dd)
print(total)

Submission status: Time Limit Exceeded

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

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

    total =  []

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

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

main()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# abc177-c
import itertools
n = int(input())
list = list(map(int, input().split()))
cumsum = 0
print(sum([(pair[0] * pair[1]) for pair in itertools.combinations(list, 2)]) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
import itertools
aha=list(itertools.combinations(a,2))
kotae=0
for i in range(len(aha)):
    #print(aha[i])
    seki=aha[i][0]*aha[i][1]
    #print(seki)
    kotae+=seki
kotae=kotae%1000000007
print(kotae)

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()
  data2 = list(map(lambda x: x*tmp, d))
  ans = (ans + sum(data2)) % MOD

print(ans)

Submission status: Time Limit Exceeded

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

import itertools
c = itertools.combinations(A, 2)
q=0
for v in c:
    q +=v[0]*v[1]%MOD
print(q%MOD)

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()))
num = 1
ans = 0
for x in a:
    for i in range(len(a)-num):
        s = x*a[num+i] % (10**9 + 7)
        ans = ans + s
    num += 1

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0

combs = list(combinations(a_arr, 2))
# print(combs)

for comb in combs:
    ans += comb[0] * comb[1]

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

Submission status: Time Limit Exceeded

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


# def amari(num):
#     return num % (10**9+7)


# a = list(map(amari, a))

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
x = 10**9 + 7
n = int(input())
a = list(map(lambda i: i % x , map(int, input().split(" "))))

ans = 0
for i, j in itertools.combinations(range(n), 2):
    ans += (a[i] * a[j]) % x

print(ans % x)

Submission status: Time Limit Exceeded

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

sum = 0

for i in range(0,n):
    a[i] = a[i] % (10**9 +7)

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

print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

print(ans%p)

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])%p
print(ans %p)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def main(N, A_list):
    mod = (10 ** 9) + 7
    tmp = []
    for i in range(len(A_list)):
        for j in range(i+1, len(A_list), 1):
            tmp.append(A_list[i] * A_list[j])

    val = 0
    for x in tmp:
        val += x

    print(val % mod)


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import numpy as np

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

MOD = 1.e9 + 7
As = [int(v % MOD) for v in As ]

val = 0

for i in range(0, N - 1):
    for j in range(i + 1, N):
        val = val % MOD
        val += (As[i] * As[j]) % MOD

print(int(val % MOD))

# print(val)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#-*-coding:utf-8-*-

import sys
import itertools

def main():
    base_numbers=[]
    mod_numbers=[]
    comb=[]
    n = int(input())
    mod = 1000000007
    ans=0
    base_numbers=list(map(int,input().split()))
    for number in base_numbers:
        mod_numbers.append(number%mod)
    comb=(list(itertools.combinations(mod_numbers,2)))

    for v1,v2 in comb:
        ans+=v1*v2%mod
    print(ans%mod)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

# b = [i % dx for i in a]

ans = 0
alist = []
for i in range(n):
    if a[i] == 0:
        continue

    for j in range(i+1, n):
        if a[j] == 0:
            continue

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

    ans = 0
    for (i, j) in combinations:
        ans += A[i] * A[j] % M
    print(ans % M)


main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

if __name__ == "__main__":

    n = int(input())
    # # y = list(input().split())
    x = map(int, input().split())

    # print(y)
    # x = [int(x) for x in y]
    # n = 4
    # x = [141421356 ,17320508 ,22360679 ,244949]

    # print(np.multiply(x))

    mod = pow(10,9) + 7

    # test1 = np.array(list(itertools.combinations(x,2)))
    test1 = itertools.combinations(x,2)

    test2 = 0
    for el in test1:
        test2 += np.prod(el)


    # test2 = np.prod(test1, axis=1)
    print(np.sum(test2)%mod)

Submission status: Time Limit Exceeded

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

mod_value = 10**9 + 7

total = 0
for i in range(len(a)-1):
    target_value = 0
    for j in range(i+1, len(a)):
        target_value += a[j]
    total += a[i] * target_value 
print(total%mod_value)

Submission status: Time Limit Exceeded

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

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)):
  if (i >= mod_const):
    i %= mod_const
  if (j >= mod_const):
    j %= mod_const
  ans += i * j
print(ans%mod_const)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    for j in range(i+1, n):
            sumpro += (a[i]*a[j])%mod
            if sumpro > mod:
                sumpro = sumpro%mod
print(sumpro)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush
from time import time
import re
setrecursionlimit(10**9)
mod=10**9+7
inf=10**18

n=int(input())
a=[int(x) for x in input().split()]
ans=0
for i in range(n):
    ans+=a[i]*sum(a[i+1:])
    ans%=mod
     
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n,*a=map(int,open(0).read().split())
r=0
for pair in itertools.combinations(a, 2):
  r+=pair[0]*pair[1]
  
print(r%1000000007)

Submission status: Time Limit Exceeded

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

ans = 0

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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

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):
    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
        sum = (sum + temp3) % MOD
#sum = sum % MOD
print(sum)

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=ans+getA*A[i]
        ans=ans%mod
    cnt+=1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())


num = input().split()
num = list(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:
from itertools import combinations
n=int(input())
ct=0
a=list(map(int,input().split()))
list1=list(combinations(a[:n],2))
for i in range(len(list1)):
    ct+=int(list1[i][0])*int(list1[i][1])
print(ct%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    number = int(input())
    num_list = list(map(int, stdin.readline().split()))
    sum = 0
    for i in range(number):
        temp = num_list[i]
        for j in range(i+1, number):
            sum += temp*num_list[j]
    print(sum % (10**9 + 7))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

ss = list(map(int, input().strip().split()))
total=0

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

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

Submission status: Time Limit Exceeded

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

r = 0

for n in range(N):
    a = A.pop(0)
    for aa in A:
        r = r + a * aa
        if r > (10 ** 9 + 7):
            r = r % (10 ** 9 + 7)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
div = [0]*N
re = div[:]
ans = 0
for i in range(N):
    div[i] = A[i] // 1000000007
    re[i] = A[i] % 1000000007

for i in range(N):
    for j in range(i+1,N):
        tmp = div[i]*re[j] + div[j]*re[i] + re[i]*re[j]
        ans += tmp % 1000000007

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import copy
    import numpy as np
    N = int(input())
    A_list = list(map(int, input().split()))
    B = copy.copy(A_list)
    i = 0
    ans = 0
    for val in A_list :
        #print("A" , val)
        #print("B", B[i])
        ans = ans + val * sum(B) - val * B[i]
        B.pop(i)
        #i += 1
        if len(B) == 0 :
            break

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num_list = list(map(int, input().split()))  # n個の数字がリストに格納される
c = 0

for i in range(n):
  for j in range(i+1, n):
    c = c + num_list[i]*num_list[j]
    
print(c%(10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
a=list(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:
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
for i, ni in enumerate(nums):
    for nj in nums[i+1:]:
        res += ni*nj
        res %= 10**9 + 7
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():

	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]
			
	print(S%(7+pow(10,9)))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

num = int(input())
nums = [int(n) for n in input().split()]
result = 0
for n1, n2 in list(itertools.combinations(nums, 2)):
    result += n1*n2

result = result % 1000000007

print(result)

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:
    x = a * b
    sumlst.append(x)

modlst = sum(sumlst)
answer = modlst % 1000000007

print(answer)

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):
    ans.append(a[i] * (sum(a) - s))
    s += a[i+1]
print(sum(ans) % (10**9 + 7))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

total = 0
mod = 1000000007

for i in range(0,n-1):
    for x in range(i+1,n):
        seki = list1[i] * list1[x] % mod
        total += seki



kotae = total % mod

print(kotae)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
an_np = np.array(an)
summary = 0
for i in range(0, n-1):
    summary = (summary + sum(an_np[i] * an_np[i+1: n] % m)) % m
print(summary)

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]
       

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
MOD = 1000000007
sum = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
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[i]%mod
        A[j]=A[j]%mod
        sum+=((A[i])*(A[j] ))
        sum=sum%mod
print(sum)

Submission status: Time Limit Exceeded

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

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