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 = input()
A = list(map(int, input().split(' ')))

bigNum = 10 ** 9 + 7
rets = [0]

def bt(track, start):
    if len(track) == 2:
        rets[0] += (track[0] % bigNum) * (track[1] % bigNum)
        rets[0] %= bigNum
        return

    for i in range(start, len(A)):
        track.append(A[i])
        bt(track, i + 1)
        track.pop()
tr = []
bt(tr, 0)
print(rets[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
total = 0
mod = 10**9+7
for i in range(N):
  for k in range(N):
    if i!=k and i<k:
      total+=(A[i]*A[k])%mod
print(total%(mod))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
numbers = list(map(int, input().split()))
 
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:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

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

print(ans % mod)

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = (s-t) % (10**9+7)
tmp = (2**1000000005) % (10**9+7)
ans *= tmp
ans %= (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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):
    for j in range(n - (i + 1)):
        res =  (res + a[i] * a[i + (j + 1)] % mod) % mod

print(res)

Submission status: Time Limit Exceeded

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

k = 10**9+7

ans = 0
for s in range(len(A)-1):
    ans += A[s]*sum(A[s+1:])

print(ans%k)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(len(A_list)):
	A_list[i] = int(A_list[i]) % (10**9 + 7)
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:
def add(arr):
    if len(arr)==1:
        return int(arr[0])
    else:
        answer=0
        for x in range(len(arr)-1):
            arr[x]=int(arr[x])
            arr[x+1]=int(arr[x+1])
            answer+=arr[0]*arr[x+1]
        answer+=add(arr[1:])
        return answer%1000000007
x=int(input())
num=input().split()
answer=add(num)
print((answer-num[-1])%1000000007)

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)):
  #print (pp[0] * pp[1]) 
  a = int(str(pp[0])[-5:])
  b = int(str(pp[1])[-5:])
  c += (pp[0] * pp[1]) % 1000000007
  #c += (pp[0] * pp[1]) %  (10 **9 + 7)
print(c % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))
m = 10**9 + 7
count = 0
for i in range (0,len(data)):
    data[i] = data[i]%m
for i in range(0,len(data)):
    for j in range(i+1,len(data)):
        count += (data[i]*data[j]) %m

print(count %m)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7

res = 0
for i in range(N-1):
    tmp = 0
    for ii in range(i+1):
        tmp += A[ii]
    res += (tmp * A[i+1]) % mod

print(res % mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

my_sum = 0
for i in range(n-1):
#    print(a[0:n-1-i])
 #   print(a[i+1:n])
    b = np.array(a[0:n-1-i])
    c = np.array(a[i+1:n])
    my_sum += np.dot(b,c)

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

res = my_sum % (10**9 + 7)

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

a=int(input())

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

sum=0

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

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

Submission status: Time Limit Exceeded

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

for i in range(0,n-1):
    for j in range(i+1,n):
        #print(nums[i],nums[j])
        multinums.append(nums[i]*nums[j])

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

Submission status: Time Limit Exceeded

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

import sys
import itertools

def main():
    numbers=[]
    comb=[]
    n = int(input())
    mod = 1000000007
    ans=0
    numbers=list(map(int,input().split()))
    comb=(list(itertools.combinations(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 = list(map(int,input().split()))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

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

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

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)
    ans = (ans + y) % z

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

div, mod = divmod(ans, 1000000007)

print(mod)

Submission status: Time Limit Exceeded

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

threshold = 1000000007
ans = 0
for i in range(N-1):
    count = 0
    for j in range(i+1, N):
        count += list_A[j]
    ans += (list_A[i] * count % threshold)
ans = ans % threshold
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = list(map(int, input().split()))
total = 0
mod = 1000000007
L = itertools.combinations(l, 2)
for a,b in L:
    a = a % mod
    b = b % mod
    sum = (a * b) % mod
    total += sum
print(total % mod)

Submission status: Time Limit Exceeded

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

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 += (As[i] * As[j]) % MOD

print(int(val % MOD))

# print(val)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N=int(input())

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

P=1000000007

z=0
bm=defaultdict(lambda:0)

for i in range(0,N-1):
    for j in range(i+1,N):
        if(0!=bm[(A[i],A[j])]):
            p=bm[(A[i],A[j])]
        else:
            p=A[i]*A[j]
            bm[(A[i],A[j])]=p
#        print(i,j,p)
        z+=p

z%=P
print(z)

Submission status: Time Limit Exceeded

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

mod = 10**9 +7
ans = 0
for i in range(len(a_s)-1):
  ans += (sum(a_s[i+1:])*a_s[i])%mod
  if ans > mod:
    ans = ans%mod
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ai = list(map(int,input().split()))
kei = 0
last = 0
S = []
for i in range(0,n-1):
    for k in range(1,n-i):
      kei = ai[i]*ai[i+k]
      S.append(kei)
last = sum(S) % (10**9 + 7)      
print(last)

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

    a=A[i]%(10**9+7)
    b=A[j]%(10**9+7)
    ans+=(a*b)%(10**9+7)

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(n):
  s1 = 0
  for j in range(i):
    s1 += a[j]
  s = (s + a[i] * s1) %mod
print(s)

Submission status: Time Limit Exceeded

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

for j in range(N):
    b = a[1][j+1:]
    b = [int(x) for x in b]
    count = (int(a[1][j])*sum(b)+count) % 1000000007
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

if __name__ == "__main__":

    n = int(input())
    y = list(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)))

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
A = input()

N = int(N)

part_A = A.split(" ")

sum0=0
for i in range(N-1):
    sum1 = 0
    for j in part_A[i+1:N]:
        sum1 = sum1 + int(j)
    sum0 = sum0 + int(part_A[i])*sum1
    
MOD = 1000000007
print(sum0%MOD)

Submission status: Time Limit Exceeded

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

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

print(Asum)

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 =  0

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

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

main()

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(lambda x: int(x), input().split()))
def fun(a, b, c):
    ans = 0
    while b:
        if b & 1:
            ans += a
            if ans > c:
                ans -= c
        a = a << 1
        if a >= c:
            a -= c
        b = b >> 1
    return ans

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

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7
A_mod = [a%MOD for a in A]

ans = 0

for i in range(1, N):
    ans = (ans + A_mod[i-1]%MOD * sum(A_mod[i:])%MOD)%MOD
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input().split())
A=[int(n) for n in S]
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:
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

for i in range(1, n):
    ans += sum(nums[:i]) * nums[i]
    ans = ans % x

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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
    ans = ans % mod

print(ans)

Submission status: Time Limit Exceeded

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

def m(i):
  return i%(10**9+7)

for i,ii in enumerate(A):
  for jj in A[i+1:]:
    #print(ii,jj,r)
    r += m(ii*jj)

print(m(r))

Submission status: Time Limit Exceeded

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

tem=0
for i in range(n-1):
    tem+=(lst[i] % (10**9+7) )*new_lst[i]
        # print(tem)
print(tem % (10**9 +7))

Submission status: Time Limit Exceeded

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

ans = 0
mod = int(1e9 + 7)
for i in range(N-1):
    for j in range(i+1, N):
        ans += (A_list[i]*A_list[j]) % mod
    ans %= mod
print(ans)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
assert(len(A) == N)
sum_now = 0
for i in range(N):
    for j in range(i+1,N):
        sum_now = (sum_now + A[i] * A[j]) % (1e9+7)
print(int(sum_now))

Submission status: Time Limit Exceeded

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

	ans = 0

	import itertools

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

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
mod =1000000007
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0]*n
for i in range(n):
    b[i] = a[i]%mod
sumpro = 0

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0
for s in range(len(A)-1):
    ans += A[s]*sum(A[s+1:])

print(np.mod(ans,10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
num_list = input().split()

mod_base = 10 ** 9 + 7

def calc_list(i, num_list):
    sum = 0
    for num in num_list[i+1:]:
        sum += int(num_list[i]) * int(num)
    return sum

sum_num = 0

for i, num_str in enumerate(num_list):
    if i+1 > len(num_list):
        break
    sum_num += calc_list(i, num_list)
    
print(sum_num % mod_base)

Submission status: Time Limit Exceeded

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

mod = 10**9 +7
ans = 0
for i in range(len(a_s)-1):
  ans += ((sum(a_s[i+1:])%mod)*a_s[i])%mod
  if ans > mod:
    ans = ans%mod
      
print(ans)

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 =  0

    for i in range(N):
        An = int(A.pop())
        for j in A:
            Am = int(j)
            total = total + (An * Am)
            
    print(total % (10**9 + 7))

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    n = int(input())
    a = map(int, input().split())
    count = 0
    for i in itertools.combinations(a, 2):
        count += i[0]*i[1]
    return count % (10**9+7)


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = list(map(int, input().split()))
total = 0
mod = 1000000007
L = itertools.combinations(l, 2)
for a,b in L:
    total += ((a % mod) * (b % mod)) % mod
print(total % mod)

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = list(map(lambda x: int(x) % mod, input().split(" ")))

print(sum((A[i] * A[j]) % mod for i in range(0,N-1) for j in range(i+1,N)) % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(out)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
N = int(input())
number_list = list(map(int, input().split()))
sum_number = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  N = int(input(""))
  in2 = input("")
  num_list = [int(x) for x in in2.split(" ")]
  
  sum = 0
  for i in range(N-1):
    for j in range(i+1, N):
      sum += num_list[i] * num_list[j]

  print(sum % (10**9+7))
 
if __name__ == "__main__":
  main()

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[i+1:n])
  ans %= 1000000000+7
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())

MOD = 1000000007

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split(" ")))

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
tmp = pow(10, 9) + 7

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

A = list(map(lambda x: x % tmp, A))

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

ans = ans % tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))
m = 10**9 + 7
count = 0
for i in range(0,len(data)):
    for j in range(i+1,len(data)):
        count += ((data[i]%m)*(data[j])%m)%m

print(count %m)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a = [int(x) for x in input().split()]
s = 0
for (i, j) in list(itertools.combinations(range(n), 2)):
    s += a[i] * a[j]
print(s % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
mod = 10**9+7
mod_sum = 0
for i in range(n-1):
    mod_sum += a[i] * sum(a[i+1:]) % mod

print(mod_sum%mod)

Submission status: Time Limit Exceeded

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

a.sort()

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
a,b = 0,0
for i in range(n-1):
  #b = 0
  b = sum(S[i+1:n]) % divisor
  #for j in range(i+1,n):
  #  b += S[j]
  #  if b >= divisor:
  #    b = b % divisor
  a = S[i]
  #tot += multmod(a,b,divisor)
  tot += a*b % divisor
  #if tot >= divisor:
  #  tot = tot % divisor

tot = tot % divisor
print(tot)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a_list = list(map(int, input().split()))
result = []

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

print(sum(result) % 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 += As[i] * As[j]

print(int(val % MOD))

# print(val)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())

num = input().split()

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():

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

    ans = 0

    for i in range(n - 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:
import itertools
n = int(input())
a = list(map(int, input().split()))
amaria = []
ans = 0
p = 10 ** 9+7
#for i in itertools.combinations(a,2):
    #ans += i[0]* i[1]
    #print(ans)
for i in range(n):
    amaria.append(a[i]%p)
for j in itertools.combinations(amaria,2):
    ans += j[0]* j[1]
print(ans % p)

Submission status: Time Limit Exceeded

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

    mod = 10**9 + 7
    answer = 0

    for i in range(0, n-1):
        sum_other = sum(a[i+1:])
        if sum_other >= mod:
            answer %= mod
        answer += a[i] * sum_other
        if answer >= mod:
            answer %= mod

    print(answer)


'''
    for i in range(n):
        sum_sub = 0
        for j in range(i+1, n):
            sum_sub += a[j]
            if sum_sub >= mod:
                sum_sub %= mod
        answer += a[i] * sum_sub
        if answer >= mod:
            answer %= mod
    print(answer)
'''

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum=0
mod = 1000000007
for v in itertools.combinations(A, 2):
    sum +=v[0]%mod *v[1]%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
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())
A = list(map(int, input().split()))
ans = 0
for i in range(n):
    A[i] %= (10**9 +7)
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:
from sys import stdin

n = int(stdin.readline().strip())
a_lst = [int(x) for x in stdin.readline().split()]
base = 10 ** 9  + 7
s = 0

for j in range(n):
  for i in range(j):
    s += a_lst[i] * a_lst[j]

s %= base
print(s)