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

for i in range(0,N):
    if A[i]%(10**9)+7==0:
        del A[i]

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

Submission status: Time Limit Exceeded

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

#list型で受け取るとき
N = int(input())
A_list = list(map(int, input().split()))  # n個の数字がリストに格納される
  
sum_ans = 0
for i in range(N):
  for j in range(i,N):
    if i!=j:
      sum_ans = sum_ans + A_list[i]*A_list[j]
ans = sum_ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(len(an)):
  for j in range(i+1,len(an)):
    sum +=  an[i]*an[j]
    sum = sum%1000000007
print(sum)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]


import itertools

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

ans = 0
a = list(itertools.combinations(seq,2))

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


print(ans)

Submission status: Time Limit Exceeded

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

mod_number = 10**9 + 7

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

ans = total % mod_number

print(ans)

Submission status: Time Limit Exceeded

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

m = 10 ** 9 + 7
def main():
    r = 0
    for i in range(n - 1):
        for j in range(i+1, n):
            r += (a[i] * a[j])
    
    print(r % m)
    return

main()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    m = 10**9 + 7
    B =[a%m for a in A]
    ans = 0
    for i in range(N-1):
        for j in range(i+1,N):
            # ans += (A[i]*A[j])%(10**9+7)
            ans += (A[i]*A[j])
    print(ans%m)

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

Submission status: Time Limit Exceeded

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


def main():
    N = int( sys.stdin.readline() )
    A_list = list(map(int, sys.stdin.readline().split()))
    
    
    mod = 10**9 + 7
    S = 0

    for i in range(len(A_list)-1):
        for j in range(i+1, len(A_list)):
            S += ( A_list[i] * A_list[j] ) % mod
            S %= mod
    
    print(S)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ass = 0

for i in range(k):
    for j in range(i+1,k):
        n1 = int(num[i])
        n2 = int(num[j])
        n3 = n1 * n2
        ass += n3

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

Submission status: Time Limit Exceeded

Solution code:
mod = 1e9+7
#lst = [] 
n = int(input()) 
l = list(map(int, input().split())) 
s=0
p=1
for i in range(0,n):
    for j in range(i+1,n):
        s+=int((l[i]*l[j])%mod)
        
print(int(s%mod))

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    a_i = A[i]
    a_other = sum(A[i+1:])
    # print(a_i)
    # print(a_other)
    total += a_i * a_other

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

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

Submission status: Time Limit Exceeded

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

tot = 0
for i in range(n):
    for j in range(i+1, n):
        tot += l[i]*l[j]
        if tot >= 10**9 + 7:
            tot %= (10**9 + 7)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(map(int, input().split()))
combi = list(itertools.combinations(A, 2))

result = 0
for c in combi:
    result += (c[0]%(10**9+7)) * (c[1]%(10**9+7))

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b = list(map(int, input().split()))
b.sort()
S=0

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

Submission status: Time Limit Exceeded

Solution code:
n=input()
b= input().split()
a = [int(_) for _ in b]
len_a = len(a)
sum=0
for n in range(0,len_a-1):
    for n2 in range(n+1,len_a):
        sum += a[n]*a[n2]
print(sum%(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(0,n-1):
  for j in range(i+1,n):
      x=l[i]*l[j]
      s=s+x
q=pow(10,9)+7
print(s%q)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

out = 0
for i in range(n - 1):
    for j in range(n - i - 1):
        k = i + j + 1
        # print(A[i], A[k])
        out += (A[i] * A[k])
        out %= mod
print(out)

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

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
at = [a[i] % mod for i in range(n)]

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum = 0

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
*a, = map(int, input().split())
sum_ = 0
for comb in list(itertools.combinations(a,2)):
    sum_ += comb[0]*comb[1]
print(sum_%1000000007)

Submission status: Time Limit Exceeded

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

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


def main():
    probC()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
#Sが長いほう
N = int(input())
A = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(int(y) for y in input().split())
b=[]
# for i in range(n):
#     print(a[i])
#     b.append(a[i])

for i in range(n):
    for j in range(i+1,n):
        # print(a[i]*a[j]%((10**9)+7))
        b.append((a[i]*a[j])%((10**9)+7))
print(sum(b)%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

MOD = 10 ** 9 + 7
S = 0
for c in list(itertools.combinations(range(N), 2)):
    S += As[c[0]] * As[c[1]] % MOD
print(S % MOD)

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]
    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):
        seki = a[i] * a[j]
        seki %= mod
        ans += seki
        ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

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

res = 0

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

print(res)

Submission status: Time Limit Exceeded

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

#list型で受け取るとき
N = int(input())
A_list = list(map(int, input().split()))  # n個の数字がリストに格納される
  
sum_ans = 0
for i in range(N):
  for j in range(i,N):
    if i!=j:
      sum_ans = sum_ans + A_list[i]*A_list[j] % (10**9+7)
ans = sum_ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

Submission status: Time Limit Exceeded

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

part_of_sum=[]
for i in range(n-1):
  part_of_sum.append(sum(li[i+1:]))

sum=0
for j in range(n-1):
  sum+=li[j]*part_of_sum[j]

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

Submission status: Time Limit Exceeded

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

B = []
for a in A:
  B.append(a%(1000000007))
sumA = 0
for j in range(len(B)):
  for i in range(j+1, len(B)):
    sumA += (B[j]*B[i])%(1000000007)
print(sumA%(1000000007))

Submission status: Time Limit Exceeded

Solution code:
D = int(1e9 + 7)
N = int(input())
M = [int(i) % D for i in input().split()]

sum_ = 0
for i, x in enumerate(M[:-1]):
    S = M[i+1:]
    sum_ += (sum(S) % D) * x
    sum_ %= D

print(sum_)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [A for A in a if a != 0]
from itertools import combinations

MOD = 10**9 + 7
ans = 0
for i,j in combinations(a, 2):
    ans = ans + (i*j)%MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(0,n-1):
    s = a[i]%1000000007
    for j in range(i+1,n):
        t = a[j]%1000000007
        res = ((res)%1000000007) + (s*t)%1000000007
print(res)

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(N):
        if (i != j and i<j):
            x=x+a[i]*a[j]


y=10**9+7
if (x>y):
    print(x%y)
else:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import itertools

def main():

    input = stdin.readline

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

    mod = (10 ** 9) +7

    ans = 0

    for i,j in itertools.combinations(range(N),2):
        ans = (ans + (A[i] * A[j])) % mod

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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(1, N-i):
        sum_ = sum_ + A[i]*A[-j]
result = sum_ % (10**9+7)
print(result)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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


def main():
    n = int(si())
    l = [int(e) for e in si().split()]
    mod, ans = 10**9+7, 0
    for i in range(n):
        for j in range(i+1, n):
            ans = (ans+(l[i]*l[j]) % mod) % mod
    print(ans)


if __name__ == '__main__':
    main()

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

print(sum % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(len(d)-1):
  temp = d.pop(0)
  ans += temp*sum(d)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
t=int(input())
arr=list(map(int,input().strip().split()))[:t]
summ=0
for i in range(0,t-1):
  for j in range(i+1,t):
    summ=(summ+((arr[i]*arr[j])%1000000007))%1000000007
print(summ%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
#####sorting a dictionary by the values#####
def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
##### naive method for testing prime or not#####
def is_prime(n):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
#####swap function#####
def swap(a,b):
    temp=a
    a=b
    b=temp
    return a,b
#####Primes till Nth#####
def seive_primes(n):
    flag=[0]*(n+10)
    flag[1]=flag[0]=1
    i=2
    while i*i<=n+1:
        if flag[i]==0:
            j=i*i
            while j<=n+1:
                flag[j]=1
                j+=i
        i+=1
    return flag
#####function that return all combination of sum(i^n)=x#####
def checkRecursive(x, n, curr_num=1, curr_sum=0): 
    results = 0 
    p = curr_num**n 
    while(p + curr_sum < x):  
        results += checkRecursive(x, n, curr_num + 1, p + curr_sum) 
        curr_num = curr_num + 1
        p = curr_num**n  
    if(p + curr_sum == x): 
        results = results + 1
    return results
#####number of minimum swaps required to sort the array#####
def findMinSwap(arr, n): 
    vec = [] 
    for i in range(n): 
        vec.append([arr[i], i])  
    vec = sorted(vec) 
    ans, c, j = -1, 0, 0
    for i in range(n):  
        if(vec[i][1] == i): 
            continue
        else:  
            vec[i][0], vec[vec[i][1]][1] = swap(vec[i][0],vec[vec[i][1]][1])
            vec[i][1], vec[vec[i][1]][1] = swap(vec[i][1],vec[vec[i][1]][1]) 
        if(i != vec[i][1]): 
            i -= 1
        ans += 1
    return ans
#####greatest common divisor of two numbers#####
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
#####least common multiplyer of two numbers#####
def lcm(a,b):
    return (a*b)//gcd(a,b)
#####function that return all the letters#####
def alphabates():
    return "abcdefghijklmnopqrstuvwxyz"
#####binary search#####
def binary_search(ls,n,flag):
    low=0
    hi=n-1
    while(low<=hi):
        mid=(low+hi)//2
        if ls[mid]==flag:
            return mid
        elif ls[mid]>flag:
            hi=mid-1
        else:
            low=mid+1
    return -1
#####Decimal to Binary(8 bits)#####
def Binary(n):
    if n==0:
        return "00000000"
    binary = "" 
    i = 0
    while n > 0 and i<=8: 
        s1 = str(int(n%2)) 
        binary = binary + s1 
        n /= 2
        i = i+1
        d = binary[::-1] 
    return d
#####quadratic#####
def qdrt(x,a,b,c):
    return a*x*x+b*x+c
#####taking an array/list as input#####
def inp():
    ls=list(map(int,input().split()))
    return ls
#####taking multiple inputs#####
def mult_inp():
    return map(int,input().split())
#####0-1 Knapsack#####
def knapSack(W, wt, val, n): 
    K = [[0 for x in range(W + 1)] for x in range(n + 1)]  
    for i in range(n + 1): 
        for w in range(W + 1): 
            if i == 0 or w == 0: 
                K[i][w] = 0
            elif wt[i-1] <= w: 
                K[i][w] = max(val[i-1]+K[i-1][w-wt[i-1]],  K[i-1][w]) 
            else: 
                K[i][w] = K[i-1][w] 
  
    return K[n][W] 
#####Main function starts from here#####
n=int(input())
ls=inp()
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=ls[i]*ls[j]
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=sorted(map(int,input().split()), reverse=True)
    ans=0
    mod=10**9+7
    for i in range(n-1):
        if a[i] == 0:
            break
        for j in range(i+1,n):
            if a[j] == 0:
                break
            ans += a[i]*a[j]
            ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
mod = 1000000007
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans += A[i]*A[j]
        ans %= 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-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:
def findProductSum(A,n):
    product = 0
    for i in range (n):
        for j in range (i+1,n):
            product += A[i]*A[j]
    return product

N = int(input())
a = list(map(int,input().split()))
print(findProductSum(a,N)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A)
MOD = 10**9 + 7

res = 0
for i in range(N-1):
    res += np.sum(np.mod(A[i] * A[i+1:], MOD)) % MOD

print(res % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(lambda x: int(x), input().split(" ")))

result = 0
MOD = 10**9+7

for i in range(len(As)-1):
    tmp = As[i] * sum(As[i+1:])
    result += tmp

result %= MOD

print(result)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7
ans = 0

for k in range(n):
    A[k] = A[k] % mod

for j in range(n):
    for i in range(j):
        tmp = A[i]*A[j] % mod
        ans = (ans+tmp) % mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
N = int(input()) 
nums = list(map(int, input().split()))
mod = 10 ** 9 + 7
nums_sum = 0
for i in range(0,N-1):
  for j in range(i+1,N):
    nums_sum += nums[i]*nums[j]
print(nums_sum % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

i = 0
Ans = 0
while i < N:
    j = i + 1
    k = 0
    while j < N:
        k += A[j]
        j += 1
    Ans += A[i] * k
    i += 1

Ans = Ans % (1000000000 + 7)
print(Ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

MOD = 10 ** 9 + 7

N = I()
A = LI()
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
def main():

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

if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    n = int(input())
    a = map(int, input().split())
    count = 0
    for i in list(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:
N = int(input())
A = list(map(int,input().split()))
B = A
ans = 0
for i in range(len(A)-1):
    for l in range(i + 1,len(B)):
        ans += A[i] * B[l]
        ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import defaultdict
readline = stdin.readline
read = stdin.buffer.read
def r_map(): return map(int, readline().rstrip().split())
def r_list(): return list(r_map())

MOD = 10 ** 9 + 7
# import numpy as np
# from numba import jit
# stdin = open('sample.txt')

def main():
    N = int(readline().rstrip())
    A = r_list()
    A.sort()
    ans = 0
    a_dic = defaultdict(lambda: 0)
    for i, a in enumerate(A[:-1]):
        for aa in A[i + 1:]:
            a_dic[a] += aa
    for a in A[:-1]:
        ans += a * a_dic[a]
    print(ans % MOD)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

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

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

Submission status: Time Limit Exceeded

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

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
A.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            continue
        ans += (A[i] * (sum(A[j:N]) % MOD)) %MOD
        break

print(ans % MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    a_list = [int(x) for x in input().rstrip().split(" ")]

    import itertools

    c = itertools.combinations(a_list, 2)

    x = 1000000007

    ans = 0
    for v in c:
        ans += v[0] * v[1]
        ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

import copy

num = int(input())
an = list(map(int, input().split()))
an_2 = copy.copy(an)

seki = []
for i in range(len(an_2)):
  for j in range(len(an_2)):
    if i < j:
      kake = an[i] * an_2[j]
      kake %= ((10 ** 9) + 7)
      seki.append(kake)
  
ans = 0
for i in range(len(seki)):
  ans += seki[i]
  
ans %= ((10 ** 9) + 7)

print(ans)