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

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

sum_ = 0
for i in range(N-1):
    sum_ = sum_ + sum(A[i]*B[i+1:])
    
result = pow(int(sum_), 1, (10**9+7))
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    ans = 0
    num = (10 ** 9) + 7
    a.sort()

    for i in range(n):
        tmp = 0
        for j in range(i+1, n):
            tmp = (a[i] * a[j]) % num
            ans += tmp
    
    ans = int(ans % num)
    print(int(ans % num))
 
resolve()

Submission status: Time Limit Exceeded

Solution code:
a=int(input())

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

sum=0

def pow_r(x, n):
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2, (n - 1) // 2)

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

print(sum%(pow_r(10,9)+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#d,t,s=map(int,input().split())
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]%(10**9+7))*(A[j]%(10**9+7))
    ans%=(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

Solution code:
def sum_of_product(arr):
    ans = 0
    MOD = 10 ** 9 + 7
    l = len(arr)
    for i in range(l - 1):
        for j in range(i + 1, l):
            ans += (arr[i]*arr[j])
    return ans%MOD

def start():
    n = int(input())
    arr = [int(x) for x in input().split(" ")]
    print(sum_of_product(arr))
start()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

com_A = combinations(A,2)
ans = 0
MOD = 10**9 + 7
for x, y in com_A:
    ans = (ans + (x * y)) % MOD

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

l = int(input())
ll = list(map(int,input().split()))
asum = 0
ll_len = len(ll)
for i in range(ll_len):
  count = l
  base  = ll[i]
  for j in range(i+1,ll_len):
    cu = base*ll[j]
    asum = asum+cu
    
mod = pow(10,9)+7
print(asum%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):
    aa = a.pop()
    # print(a,aa)
    ans +=  (aa * sum(a)) % mod
    ans %= mod

print(ans%mod)

Submission status: Time Limit Exceeded

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

goukei = 0
B = A
for i in range(N):
    a = A[0]
    del B[0]
    Bgoukei = sum(B)
    goukei = goukei + a*Bgoukei


k = 10**9 + 7
print(goukei%k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
ans=0
for i in range(n-1):
    
    for j in range(1+i,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()))


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n - 1):
    for l in range(i + 1, n):
            k += a[i] * a[l]

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

Submission status: Time Limit Exceeded

Solution code:
n = input()

max = 10**9 + 7

a_list = [int(a) % max for a in input().split(" ")]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#d,t,s=map(int,input().split())
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]
    ans%=10**9+7
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
A=list(map(int,input().split()))
AC=list(itertools.combinations(A,2))
x=0
for i in range(n*(n-1)//2):
  x+=AC[i][0]*AC[i][1]%(10**9+7)
print(x%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
mod = 1e9+7

for i in range(N-1):

    if A[i] > mod:

        A[i] = A[i]%mod

    for j in range(i+1, N):

        if A[j] > mod:
        
            A[j] = A[j]%mod
        
        ans += A[i]*A[j]

ans = int(ans%mod)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

result = 0

for a, b in itertools.combinations(A, 2):
    result += (a%mod) * (b%mod) % mod
    result = result % mod

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
MODINT = 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 %= MODINT
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def main():
  N = int(input())
  As = list(map(int, input().split()))
  w = 0

  c = combinations(As,2)
  for i in c:
    w = w + (i[0] * i[1])
  print(w % 1000000007)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

total = 0

for i in range(N):
    #print(i, A[i])
    sum = 0
    start = i + 1
    for j in range(start, N):
        #print(i, j)
        sum = sum + A[j]
    #print(A[i], sum)
    total = (total + A[i] * sum) % 1000000007

print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools

num = int(input())
nums = input()
lst = []

for i in range(num):
  lst.append(int(nums.split()[i]))

pairs = list(itertools.combinations(lst, 2))

total = 0

for item in pairs:
  total += item[0] * item[1]

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

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(int(y) for y in input().split())
b=[]
c=[]
for i in range(n):
    b.append(a[i]%((10**9)+7))

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

Submission status: Time Limit Exceeded

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

d=0
mod = 1000000007
import itertools as it
b=list(it.combinations(a,2))
for i in range(len(b)):
    c=((b[i][0] % mod) * (b[i][1] % mod)) % mod
    d+=c%mod
    d=d%mod
print(d)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-1):
    ans = (ans + A[i] * sum(A[i+1:])) % int(1e9 + 7)

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7

def findProductSum(A, n):
    product = 0
    for i in range(n):
        for j in range(i + 1, n):
            product = (product + A[i] * A[j]) % MOD
    return product

n = int(input())
a = [int(_) for _ in input().split()]
print(findProductSum(a, n))

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
An = [int(i) for i in input().split()]

sum = 0
for i in range(N - 1):
    Ai = An[i]
    for j in range(i + 1, N):
        Aj = An[j]
        sum += Ai * Aj

mod = int(math.pow(10, 9) + 7)

print(sum % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
keisu = [0]*n

for i in range(n):
    keisu[i] += sum(a[:i])


for i in range(n):
    ans += a[i] * keisu[i]

        
        

print(ans%(1000000000+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools
z=[]
z2=[]
b=int(input())
a=map(int, input().split())
z=[i for i in a]
b=list(itertools.combinations(z, 2))
z2=sum(((i[0]*i[1]) for i in b))
print(z2%((10**9)+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
*A,=map(int,input().split())
M=1000*1000*1000+7
S=0
for i in range(N-1):
  for j in range(i+1,N):
    S+=A[i]*A[j]
    
print("{}".format(S%M))

Submission status: Time Limit Exceeded

Solution code:
def sumPair(A):
    L = len(A)
    M = 1000000007
    total_sum = 0
    
    for i in range(0, L):
        for j in range(i+1, L):
            pair_m = A[i] * A[j]
            total_sum = (total_sum + pair_m) % M
    return total_sum
        

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import math
    n = int(input())
    # a_n = [-1] * (n + 1)
    a_n = [-1]
    hoge = list(map(int, input().split()))
    a_n.extend(hoge)
    sum_ = 0
    # for i in range(1, n):
    #     for j in range(i + 1, n + 1):
    #         sum_ += (a_n[i] * a_n[j]) % (10E08 + 7)
    # print(int(sum_ % (10E08 + 7)))
    for i, a_i in enumerate(a_n, 0):

        if i == 0:
            continue
        # for j in range(i + 1, n + 1):
        for j, a_j in enumerate(a_n[i + 1:], i):
            sum_ += (a_i * a_j) % (10E08 + 7)
    print(int(sum_ % (10E08 + 7)))
resolve()

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):
  for j in range(i+1, len(a_s)):
    ans += ((a_s[i]*a_s[j])%mod)
    if ans > mod:
      ans = ans%mod
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
lst = [int(i) for i in input().split()]
lst = sorted(lst)
count = 0
d_lst = []
for i in range(len(lst)):
    for j in range(i+1,len(lst)):
    # print(i,j)
        a = lst[i] * lst[j]
        if lst[j] in d_lst:
            continue
        else:
            if lst[i] == lst[j]:
                d_lst.append(lst[j])
                count += a
            else:
                count += a
    
if count > ( 10**9 + 7 ):
    print(count % (10**9 + 7))
else:
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_list=[int(i) for i in input().split()]

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


print(sum%MOD)

Submission status: Time Limit Exceeded

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

print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[]
b=0
for i in range(len(A)-1):
    for j in range(len(A)-i-1):
        a=A[i]*A[i+j+1]
        if a<(10**9+7):
            
        
            B.append(a)
        else:
            c=a%(10**9+7)
            B.append(c)
        b+=B[-1]
        if b>=(10**9+7):
            b=b%(10**9+7)
print(b)

Submission status: Time Limit Exceeded

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

n = i_in()
a = l_in(int)

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

ans %= const
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def sum_of_product(arr):
    ans = 0
    MOD = 10 ** 9 + 7
    l = len(arr)
    for i in range(l - 1):
        for j in range(i + 1, l):
            ans = (ans % MOD) + ((arr[i] % MOD * arr[j] % MOD)%MOD) % MOD
    return ans

def start():
    n = int(input())
    arr = [int(x) for x in input().split(" ")]
    print(sum_of_product(arr))
start()

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


sum = 0
D = set(range(N))
E = set()
for i in D:
    E.add(i)
    tmp = 0
    for j in D - E:
        tmp += A[j]
    sum += A[i] * tmp

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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):
        r += ((a[i] % m) * (sum(a[i+1:]) % m))
    print(r % m)
    return

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools 
MOD = 10**9+7

n = input()
a = [(i, int(k)) for i, k in enumerate(input().split())]
combs = itertools.combinations(a, 2)
s = 0
for comb in combs:
    i, a = comb[0]
    j, b = comb[1]
    if i < j:
        s += a*b
print(s%MOD)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

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

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

    def LII_split():
        return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    As = LII_split()

    import numpy as np
    left = np.array(list(reversed(As)))
    right_list = []
    for i in range(len(As)):
        temp = As[:len(As)-i-1]
        for _ in range(i+1):
            temp.append(0)
        right_list.append(temp)
    # print(right_list)
    right = np.array(right_list).reshape(N, N)

    # print(right)
    # print(left)

    s = sum(np.matmul(left, right))
    print(s % (10 ** 9 + 7))
    # for i in range(N):
    #     for j in range(i + 1, N):
    #         s += As[j] * As[i]
    #         if s > 10 ** 9 + 7:
    #             s %= 10 ** 9 + 7
    # print(s)
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')
import sys
import itertools
import copy


def main():
    N = I()
    a_list = LI()
    # print(a_list)
    # print(list(range(N)))
    # print(list(itertools.combinations(list(range(N))), 2))
    # print(list(itertools.combinations([1, 2, 3], 2)))
    cnt = 0
    for i in list(itertools.combinations(list(range(N)), 2)) :
        # print(i[0])
        if i[0] < i[1]:
            tmp = a_list[i[0]] * a_list[i[1]] 
            cnt += tmp
    print(cnt % (10**9 + 7))
    # L = LLIN(N)

    #     if T[-i]
    # if D / T <= S:
    #     print('Yes')
    # else:
    #     print('No') 
    # cnt = 0
    # for l in L:
    #     num = l[0] ** 2 + l[1] ** 2 
    #     if num <= D ** 2:
    #         cnt+=1
    # print(cnt)
    # print(row)
    # total = sum(row)
    # target = total - K
    # if K == total:
    #     print(1)
    #     sys.exit()
    # col = []
    # for w in range(W):
    #     cnt = 0
    #     for h in range(H):    
    #         print(A[h][w])
    #         if A[h][w] == '#':
    #             cnt += 1
    #     col.append(cnt)
    # print(col)
    # ans = 0
    # for w in range(W):
    #     for h in range(H):
    #         if A[h][w] == '#':
    #             if col[w] + row[h] - 1 == target:
    #                 print(str(h) + str(w))
    #                 ans +=1
    #         else:
    #             if col[w] + row[h] == target:
    #                 print(str(h) + str(w))
    #                 ans +=1
    # print(ans)
    #     for  in x:


    # print('AC x ' + str(cnt['AC']))
    # print('WA x ' + str(cnt['WA']))
    # print('TLE x ' + str(cnt['TLE']))
    # print('RE x ' + str(cnt['RE']))
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=input()
A=list(map(int,input().split()))
gou=0
for a in itertools.combinations(A,2):
    if a[0]*a[1]>10**9+7:
        gou+=(a[0]*a[1])%(10**9+7)
    else:
        gou+=a[0]*a[1]

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

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(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:
def ProgramC():
    
    num = int(input())
    
    data = list(map(int,input().split()))

    count = 0

    for i in range(num-1):
        
        count = count + data[i]*sum(data[i+1:])

    print(count%(pow(10,9)+7))

if __name__ == '__main__':
    ProgramC()

Submission status: Time Limit Exceeded

Solution code:

import numpy as np


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    l = np.array(l)

    tot = 0
    for i in range(n):
        tot += (l[i] * (np.sum(l[i + 1:n], dtype='int64') % (10 ** 9 + 7))) % (10 ** 9 + 7)
        '''
        if tot >= 10**9 + 7:
            tot %= (10**9 + 7)
        '''

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
input1 = input()
input1 = input1.split()
A = []
sum = 0
for i in input1:
    A.append(int(i))
for i in range(N):
    for j in range(i+1,N):
        sum = sum + A[i]*A[j]
print(sum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

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

s=sum(((ai*aj)%(10**9+7) for ai,aj in it.combinations(A,2)))
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a =[int(x) for x in input().split()]
ans = 0
ans2 = 0
b = 10**9 + 7
for index,i in enumerate(a):
    for j in a[index+1:]:
        ans =  (ans + ((i%b) * j))%b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
S = 0
for i in range(N - 1):
  T = 0
  for j in range(N - i - 1):
    # print(As[i], As[i + 1 + j])
    T += As[i + 1 + j]
  T = T % 1000000007
  S += As[i] * T
print(S % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = stdin.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))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
A = np.array(list(map(int, input().split())))

mod = 10**9+7

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

Submission status: Time Limit Exceeded

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

d = 10 ** 9 + 7

total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += (lista[i] * lista[j]) % d
total %= d
print(total)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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]
print(ans%M)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
tokens = itertools.chain.from_iterable(map(str.split, sys.stdin))

mod = 1000000007
n = int(next(tokens))
a = [int(next(tokens)) for _ in range(n)]

from numba import njit
import numpy as np
a = np.array(a, dtype=np.int64) % mod

@njit('i8(i8[:])')
def fun(a):
    m = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            m = (m + a[i] * a[j]) % mod
    return m

ans = fun(a)
print(ans)

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

Submission status: Time Limit Exceeded

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



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

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