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())
n_list = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
num_list = [n % mod for n in n_list]
a_list = []
ans = 0

while len(num_list) > 1:
    x = num_list[0]
    num_list.remove(x)
    a_list.append((x * (sum(num_list) % mod)) % mod)

ans_list = [n % mod for n in a_list]
for i in range(len(ans_list)):
    ans += ans_list[i]
    ans = ans % mod
ans = sum(ans_list) % mod

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

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 = product + A[i]*A[j] 
    return product%1000000007
   
if __name__=="__main__": 
    n = input()
    n = int(n)
    A = list(map(int, input().split()))  
   
    print(findProductSum(A, n))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
i_m=9223372036854775807
def inin():
    return int(input())
def stin():
    return input()
def spin():
    return map(int,stin().split())
def lin():                           #takes array as input
    return list(map(int,stin().split()))
def matrix(n):
    #matrix input
    return [list(map(int,input().split()))for i in range(n)]

################################################
def string2intlist(s):
    return list(map(int, s))

def calculate_sum(a, N): #sum of a to N
    # Number of multiples 
    m = N / a 
    # sum of first m natural numbers 
    sum = m * (m + 1) / 2
    # sum of multiples 
    ans = a * sum
    return ans
def series(N):
    return (N*(N+1))//2

def count2Dmatrix(i,list):
    return sum(c.count(i) for c in list)

def modinv(n,p):
    return pow(n,p-2,p)

def GCD(x, y): 
    x=abs(x)
    y=abs(y)
    if(min(x,y)==0):
        return max(x,y)
    while(y): 
        x, y = y, x % y 
    return x
def LCM (x, y):
    return (x * y) // GCD(x, y)
    
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l
def isprime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
prime=[]
def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
q=[]       
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j
# d = {}
 
"""*******************************************************"""
n=inin()
a=lin()
temp,s,total=0,0,0
for i in range(n):
    temp = a[i] * sum(a[i+1:])
    s = temp%1000000007

    total = (total+s)%1000000007

print(total)

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
P = 0
A_l = [num% (10**9+7) for num in A]
 
for i in range(N):
  sum=0
  for j in range(i+1,N):
    sum += A_l[j]
  P += A_l[i]*sum
    
ans = P%(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
c=0
for i in range(len(A)):
  c+=A[i]*(sum(A)-A[i]%MOD)
print(c//2%MOD)

Submission status: Time Limit Exceeded

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

for (i, j) in list(itertools.combinations(a, 2)):
    s += i * j
print(s % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = [int(i) for i in input().rstrip().split()]
A = np.array(A)
sum = 0

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


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

Submission status: Time Limit Exceeded

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

    M = 10 ** 9 + 7

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


main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

A_2=list(itertools.combinations(A,2))

def Kake(x):
    return (x[0]*x[1])%1000000007

A_3=map(Kake,A_2)

S=sum(A_3)

print(S%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int, input().strip().split()))
sum=0
for i in range(0,n-1):
    minsum=0
    for j in range(i+1,n):
        minsum += x[j]
        if(minsum>=1000000007):
            minsum-=1000000007
    sum += x[i]*minsum
sum%=1000000007
print(sum)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

temp_sum=0
for i in range(N):
    temp = sum(A[i+1:])%mod
    temp_sum += (temp*A[i])%mod

ans = temp_sum%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

sum_list =[p[i]*p[t] for i in range(a) for t in range(a) if i<t ]
num = np.sum(sum_list)
num = num%mod
print(num)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
alist = list(map(int, input().split()))
result = 0
amari = 0
nmod = 10 ** 9 + 7
    
for i in itertools.combinations(alist, 2):
  if i[0] == nmod or i[1] == nmod:
    continue
  else:
    amari = ((i[0] % nmod) * (i[1] % nmod)) % nmod
    result = (result + amari) % nmod
  
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())

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

a = [i for i in a if i != 0]

ans = 0
alist = []
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        t = (a[i] * a[j]) % dx
        alist.append(t)

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

ans %= dx
print(ans)

Submission status: Time Limit Exceeded

Solution code:
strn = input()
n = int(strn)
stra = input().split()
 
a = []
for i in range(n):
  a.append(int(stra[i]))
 
s = 0
for i in range(n):
  for j in range(i+1,n):
	
    #print(str(a[i]) + ' ' + str(a[j]) +' ' + str(a[i]*a[j])+ ' ' +  str(a[i]*a[j]  (10**9 + 7))+' ' +   str(s))
    s += ((a[i] * a[j]))
 
 
 
 
    
print(s%(10**9+7))

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):
    i = i%(10**9+7)
    j = j%(10**9+7)
    c +=(i*j)%(10**9+7)
print(c%(10**9+7))

Submission status: Time Limit Exceeded

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

num = int(input())


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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

def main():
    n = int(input())
    A_ = [int(x) for x in input().split()]
    A = [a for a in A_ if a != 0]
    N = len(A)

    mod = 10**9+7
    PR = 2
    order = [1]
    x = PR
    while x != 1:
        order.append(x)
        x *= PR
        x %= mod

    order_l = len(order)
    where = np.zeros(mod, int)
    for i in range(order_l):
        where[order[i]] = i
    prevCnt = np.zeros(mod, int)
    resCnt = np.zeros(mod, int)
    for n in range(N):
        if A[n] != 0:
            prevCnt[where[A[n]]] += 1
            resCnt[(A[n] * A[n]) % mod ] -= 1
    N_=1
    while N_ < 2*len(prevCnt): N_ *= 2
    nf = np.zeros(N_,int)
    nf[:len(prevCnt)]=prevCnt
    nf=np.fft.rfft(nf)
    fftRes = np.rint( np.fft.irfft(nf*nf))
    for r in range(len(fftRes)):
        if fftRes[r] != 0:
            resCnt[order[r % order_l]] += fftRes[r]
    ans = 0
    for p in range(mod):
        if resCnt[p] != 0:
            ans += (resCnt[p] // 2) * p
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums_list = list(map(int, list(input().split())))  # 各数字はint

sum = 0
for i, numi in enumerate(nums_list):
    for j, numj in enumerate(nums_list):
        if i < j:
            product = numi * numj
            amari = product % (10**9 + 7)
            sum += amari

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sigma = 0
for i in range(len(a)-1):
  start = a[i]
  after = sum(a[i+1:])
  if after >= (10**9 + 7):
    after = after % (10**9+7)
  sigma = sigma + start * after
  if sigma >= (10**9 + 7):
    sigma = sigma % (10**9+7)

print(sigma)

Submission status: Time Limit Exceeded

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

def main(N, A_list):
    num = len(A_list)
    tmp = []
    for i in range(0, num, 1):
        for j in range(i+1, num, 1):
            tmp.append(A_list[i] * A_list[j])

    val = sum(tmp) % ((10 ** 9) + 7)
    print(val)


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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


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

print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while len(A)!=0:
    f = A.pop(0)
    total  += f*sum(A)

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

Submission status: Time Limit Exceeded

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

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

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
sum = 0
k = 0
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        k += a[j]

    
    sum += a[i] * k

    k = 0
        
ans = np.mod(sum,10**9+7)

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input()) 
l=list(map(int,input().split())) 
s=0 
i=0
while(i<len(l)): 
  s=s+(l[i]*l[i+1])

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
n = int(input())
l = list(map(int,input().split()))
nums = []
for v in itertools.combinations(l, 2):
    nums.append(v[0]*v[1])
S = np.sum(nums)
print(S%(10**9+7))

Submission status: Time Limit Exceeded

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

data = []

for i in range(0, len(a)-1) :
        for j in range(1, len(a)) :
                try:
                        data.append(a[i]*a[j+i] % (10**9+7))
                except:
                        continue

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

Submission status: Time Limit Exceeded

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

sum=0
mod = 1000000007

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(len(A_int_list)):
    ans += A_int_list[i] * sum(A_int_list[i + 1:])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

n=int(input())
#a=[]
b=1000000007
sum=0

#a=(int(a) for a in input().split()) 
a = list(map(int, input().split()))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0

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


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

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]
        sum_ %= 1_000_000_007

print(sum_)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort(reverse=True)
M = 1000000007
while len(a) != 1:
    fast = a.pop(0)
    for i in a:
        ans += fast * i
print(ans % M)

Submission status: Time Limit Exceeded

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

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

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

print(sum)

Submission status: Time Limit Exceeded

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

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

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):
        if idx + 1 == len(A):
            break
        total += i * sum(A[idx + 1:])
    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()))

mod = 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
n_list = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
num_list = [n % mod for n in n_list]
a_list = []
ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        a_list.append((num_list[i] * num_list[j]) % mod)

ans_list = [n % mod for n in a_list]

for i in range(len(ans_list)):
    ans += ans_list[i]
    ans = ans%mod

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):
  total += A[i] * sum(A[i+1:])
  total %= 10 ** 9 + 7
print(total)

Submission status: Time Limit Exceeded

Solution code:

n=int(input())
#a=[]
b=1000000007
sum=0

#a=(int(a) for a in input().split()) 
a = list(map(int, input().split()))

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
alist = list(map(int, input().split()))
result = 0
amari = 0
nmod = 10 ** 9 + 7
    
for i in itertools.combinations(alist, 2):
  amari = ((i[0] % nmod) * (i[1] % nmod)) % nmod
  result = (result + amari) % nmod
  
print(result)

Submission status: Time Limit Exceeded

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n = int(input())
    a = readInt()
    ans = 0
    for i in range(n-1):
        for j in range(i+1,n):
            ans += a[i] * a[j]
            ans %= mod
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
p=Counter(sorted(combinations(a,2)))
r=0
m=10**9+7
for q,c in p.items():
	i,j=q
	r+=i*j*c
print(r%m)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(0, N):
  for j in range(0, N):
    if i > j:
      sum += int(A[i]) * int(A[j])

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

Submission status: Time Limit Exceeded

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

combi = itertools.combinations(list(range(n)),2)

ans = 0

for i in combi:
  ans += (A[i[0]] * A[i[1]]) 
  ans = ans %(10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

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

num = int(input())

def print_sum():
  an = list(map(int, input().split()))

  ans = 0

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

  print(ans)
  
print_sum()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

k = 1000000007

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

if ans>1000000007:
    print(ans%k)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
MOD = 1000000007

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

answer = 0
comb_list = list(itertools.combinations(A, 2))
for c in comb_list :
    answer += int(c[0]) * int(c[1]) 
print (answer % MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

answer = 0
mod = 1000000007
for i in range(N-1):
  total = sum(A[i+1:])
  multi = ((A[i] % mod) * (total % mod)) % mod
  answer = (answer + multi) % mod
print(str(answer))

Submission status: Time Limit Exceeded

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

def calc():
    total = 0
    for i in range(N):
        a = nums[i]
        b = sum(nums[i+1:])
        total += a*b
    return total

print(calc() % (1000000000+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(nums)):
  i_a = nums[0]

  #print(i_a,"=かけられる数")
  del nums[0]
  #print("削除後",nums)

  for j in range(len(nums)):
    #print("かけられる数",i_a,"かける数",nums[j])
    sum += i_a * nums[j]


print(sum%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
a=list(map(int, input().split()))
mod=10**9 + 7
ans=0
for pair in itertools.combinations(a, 2):
    ans+=(pair[0]*pair[1])%mod

print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

total = 0


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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
l = LI()
ans = 0

for i in range(n-1):
    j = i + 1
    while j <= n-1:
        buf = (l[i] * l[j])# % mod
        ans = ans + buf
        j += 1

print(ans % mod)

Submission status: Time Limit Exceeded

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

LA = len(A)

i = 0
j = 0
SUM = 0

for i in range(LA):
    for j in range(LA):
        if j <= i:
            continue
        SUM = SUM + (A[i] * A[j])


        
print(SUM % 1000000007)

Submission status: Time Limit Exceeded

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

ans = 0
i = 0
j = 0
for i,j in itertools.product(range(0,N), range(0,N)):
  if i < j:
    ans = ans + A[i]*A[j] % (10**9+7)
    ans = ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

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

main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
p=Counter(sorted(combinations(a,2)))
r=0
m=10**9+7
for q,c in p.items():
	i,j=q
	r+=i*j*c%m
print(r%m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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


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

print(total)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def mo(v):
    return v % 1000000007


n = int(input())
a = mo(np.array(list(map(int, input().split()))))
s = 0
for i in range(0, n - 1, 1):
    for j in range(i + 1, n, 1):
        s += mo(a[i] * a[j])
print(mo(s))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

combi = itertools.combinations(list(range(n)),2)

ans = 0

for i in combi:
  ans += (A[i[0]] * A[i[1]]) % (10 ** 9 + 7)
  
print(ans % (10 ** 9 + 7))