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

Submission status: Time Limit Exceeded

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

sum = 0
j = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int, input().split()))
nums.append(0)
len_nums = [0]

for i in range(n):
  len_nums.append(sum(nums[:i+1]))

result = 0
for x, y in zip(nums,len_nums):
  result += x * y

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0
A.sort(reverse=False)

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

lst = input().split()

for i in range(N):
   lst[i] = int(lst[i])

sum = 0

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

s = 10**9 + 7

if sum < s:
   print(sum)
else:
   print(sum % s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

line = input()
arr = [int(x) for x in line.split(" ")]

sum = 0

for i in range(num):
  for j in range(i+1, num):
    sum += arr[i]*arr[j]
    sum %= 1e9 + 7
  
print(int(sum))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
P=10**9+7
a=[int(i) for i in input().split()]
b=[0 for i in range(P)]
for i in range(N):
    b[a[i]]+=1
M=1<<19
c=np.zeros(M)
for i in range(P-1):
    c[i]=b[pow(2,i,P)]
X=[int(i+0.1) for i in np.real(np.fft.ifft(np.fft.fft(c)*np.fft.fft(c)))]
ans=0
for k in range(M):
    ans+=X[k]*pow(2,k,P)
for i in range(N):
    ans-=(a[i]*a[i])%P
print((ans//2)%P)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(cnt%mod)

Submission status: Time Limit Exceeded

Solution code:
MOD=1000000007
N=input()
A = [int(x) for x in input().split()]
l=len(A)
s=0
for i in range(l):
    B=A[i+1:l]
    s+=A[i]*sum(B)
print(s%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=0

for i in range(n):
  l=i+1
  for l in range(i+1,n):
   
    ans=ans+x[i]*x[l]
    
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
input = [int(s) for s in input().split()]
ans = 0
for i in range(N-1):
    ans = ans + input[i]*sum(input[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 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()))
A = []
mod = 10 ** 9 + 7
for a_ in A_:
    a = a_ % mod
    A.append(a)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(0,n-1):
    total += nums[i]*sum(nums[i+1:n])

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

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split(" ")))
 
    mod = 10**9+7
    res = 0

    for i in range(N-1):
        for j in range(i, N):
            if i >= j: continue
            res += A[i] * A[j]
    print(res % mod)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

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

    mod = 10**9+7
    res = 0
    before = 0
    for i, j in combinations(A, 2):
        res += i * j
    print(res % mod)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD=1000000007
N=input()
A = [int(x) for x in input().split()]
l=len(A)
s=0
for i in range(l):
    B=A[i+1:l]
    s+=A[i]*sum(B)
print(s%MOD)

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            aa = aa + a[j]
    number = number + ((a[i] % mod) * (aa % mod))
    number = number % mod
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            aa = aa + a[j]
    number = number + ((a[i] % mod) * aa)
    number = number % mod
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0

for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            aa = aa + a[j]
    number = number + (a[i] * aa)
    number = number % mod
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(s) for s in input().split()]
ans = int(0)
temp = int(0)
MOD = int(1000000007)
for i in range(N-1):
  temp = sum(a[i+1:N])
  temp = temp % MOD
  temp = temp * a[i]
  temp = temp % MOD
  ans += temp
  ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
aa=list(map(int,input().split()))
accumulation=[]
total=0

for i in range(n):
    aacut=aa[:(i+1)]
    accumulation.append(sum(aacut))

for i in range(n):
    total+=aa[i]*(accumulation[n-1]-accumulation[i])

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

Submission status: Time Limit Exceeded

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

sm = sum(A)

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

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0

for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            aa = aa + a[j]
    number = number + (a[i] * aa)
    if number >= mod:
        number = number % mod
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0



for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            aa = aa + a[j]
    number = number + (a[i] * aa)
    if number >= mod:
        number = number - mod
amari = number % mod
print(amari)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(e) for e in input().split()]
sum = 0
asum = 0
for i in A :
    asum = asum + i*i
    for j in A:
        sum = sum + i*j
sum = ((sum - asum)/2)%1000000007

print(int(sum))

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().rstrip().split(" ")

l = []
for i in range(n):
    l.append(int(a[i]))

x = 0
MOD = 1000000007
for i in range(n - 1):
    for j in range(i + 1, n):
        x += (l[i] * l[j]) % MOD
        x = x % MOD
#        print(str(i) + " * " + str(j))
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0



for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        aa = aa + a[j]
    number = number + (a[i] * aa)
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(max % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0



for i in range(n):
    aa = 0
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            aa = aa + a[j]
    number = number + (a[i] * aa)
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
tmp = list(map(int, input().split()))
A = [a % M for a in tmp]
ans = 0
for i in range(1,n):
    ans += (A[i-1] * ((sum(A[i::])%M)))%M
print(ans%M)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = 0
lis = 0
for i in range(N-1):
  lis = 0
  for j in range(i+1, N):
   lis = lis + A[j]
  S = S + A[i] * lis

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0


for i in range(n):
    for e in range(n-i-1):
        j = i+e+1
        if i != j:
            number = number + (a[i] * a[j])
amari = number % mod
print(amari)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    mod = 10**9+7
    a_sum = sum(A)
    ans = 0
    for i in range(len(A)-1):
        ans += A[i] * (a_sum - sum(A[:i+1])) % mod
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

def mod(x):
  return x%((10**9)+7)
n=int(input())
a_list=list(map(int,input().split()))
sum_list=[]
sum_list=[i[0]*i[1] for i in itertools.combinations(a_list,2)]
s=sum(sum_list)
s=mod(s)
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
Ak = list(map(int,input().split()))
s = 0
for i in range(1,n):
    K = int(Ak[i])
    
    T = int(sum(Ak[0:i]))
    s = s + K*T
print(s % (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):
    ans += (A[i] * sum(A[(i + 1):]))

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 7+1000000000

amari = 0

for i in range(n):
    for e in range(n):
        if i != e:
            number = number + (a[i] * a[e])
amari = int((number % mod) / 2)
print(amari)

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


MOD = pow(10, 9)+7

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

def mod(x):
  return x%((10**9)+7)
n=int(input())
a_list=list(map(int,input().split()))
sum_list=[]
for i in itertools.combinations(a_list,2):
  sum_list.append((i[0]*i[1]))

s=sum(sum_list)
s=mod(s)
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=input()
m=0
MOD = 10**9 + 7
from itertools import combinations
for i,j in combinations(map(int,input().split()),2):
    k=i*j
    m+=k
v=m%MOD
if m<=MOD:
    print(m)
else:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools as it

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

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

print(sum1)

# sum = 0
# for i in range(n):
#     sum += 1 / a[i]
#print(sum)

# ans = int(sum * np.prod(a))
# print(ans % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N= int(input())
A= list(map(int,input().split(' ')))
 
ans = 0
for i in range(len(A)-1):
  ans += A[i] * sum(A[i+1:])

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import operator

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

for i in range(len(list(itertools.combinations(A, 2)))):
    n = list(itertools.combinations(A, 2))
    if n[i][0]*n[i][1] >= (10**9+7):
        num = n[i][0]*n[i][1]%(10**9 +7)

    AA.append(n[i][0]*n[i][1])


if sum(AA) >= (10**9 +7):
    print(sum(AA)%(10**9 +7))
else:
    print(sum(AA))

Submission status: Time Limit Exceeded

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

    mod = 10**9 + 7
    answer = 0

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

    print(answer)


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

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
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)%(pow(10,9)+7)
print(ans)

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

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

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

    total = 0

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

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

main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
n = int(input())
s = enumerate(input().split(" "))

list = [(int(x[1]) %(10**9 + 7)* int(y[1]) % (10**9 + 7))%(10**9 + 7) for x, y in list(product(s, repeat=2)) if x[0] < y[0]]

soma = 0
for e in list:
    soma = (soma %(10**9 + 7) + e %(10**9 + 7)) %(10**9 + 7)

print(soma)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = int(0)
m = int(1000000007)
n = int(1)

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

print(a % m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
  for j in range(i+1, len(A)):
    ans += A[i]*A[j]
    if ans > 10**9+7:
      ans %= 10**9+7
print(ans)

Submission status: Time Limit Exceeded

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

 
for i in range(N-1):
    for j in range(i+1,N):
        
        sum = sum + list1[i]*list1[j]
answer = divmod(sum, 10**9+7)
print(answer[1])

Submission status: Time Limit Exceeded

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

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(0,len(A)):
    raw = 0
    for j in range(i+1,len(A)):
        raw += A[j]
        raw = raw % MOD
    ans += A[i] * raw
    ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

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

for i in range(1,N):
    tmp = A[i:]
#    print(tmp)
    ans += A[i-1]*sum(tmp)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
W = 0
ans = 0
count = 1
for i in A:
    W = i * sum(A[count:N])
    ans += W
    count += 1
print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

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

a = np.array(a_row)
MOD = 1000000007
ans = 0

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

print(ans)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())

xlist = input().split(" ")
ylist = []

for num in xlist:
    ylist.append(int(num))


    """
pairs = itertools.combinations(ylist, 2)
answer = 0
for pair in pairs:
    answer += pair[0] * pair[1]

print(answer % (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]
    return product


print(findProductSum(ylist,N ) %  (10**9 +7 ))

Submission status: Time Limit Exceeded

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

n=int(input())  #->n=5
ai=list(map(int,input().split()))  #->nl=[1,2,-,n]

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

print(temp)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
a = list(map(int,input().split()))
count = 0
for k in range(num):
    a[k] = a[k] % (10**9 + 7)
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:
import itertools
from heapq import heapify, heappop, heappush, heappushpop
nCr = {}






class PriorityQueue:
    def __init__(self, heap):
        '''
        heap ... list
        '''
        self.heap = heap
        heapify(self.heap)

    def push(self, item):
        heappush(self.heap, item)

    def pop(self):
        return heappop(self.heap)

    def pushpop(self, item):
        return heappushpop(self.heap, item)

    def __call__(self):
        return self.heap


heap = []  # ヒープといっても順序を工夫したただのリスト

q = PriorityQueue(heap) #ここでインスタンスを作ってます
n = int(input())
l = list(map(int, input().split()))
mod = 1000000007
result = []
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        result.append([l[i], l[j]])
for a,b in result:
    q.push(((a % mod) * (b % mod)) % mod)
print(sum(heap) % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
grid = []
for i in range(2):
    array = list(map(int, input().strip().split()))
    grid.append(array)

lists = []
    
for j in range(grid[0][0]-1):
    for i in range(grid[0][0]-1-j):
        lists.append(grid[1][j]*grid[1][j+i+1])

print(sum(lists)%(1000000007))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# import sys
import itertools

N = int(input())
A = np.array(list(map(int, input().split())))
A = A % (1E+9+7)

C = np.array(list(itertools.combinations(A,2)))
# print(C[:,0])
# print(len(C))

answer = np.dot(C[:,0],C[:,1])

# product = 0
# product_sum = 0
# for i in range(len(C)):
#     product = ((C[i][0] % (1E+9+7)) * (C[i][1] % (1E+9+7)))
#     product_sum = product_sum + product
#     product_sum = product_sum % (1E+9+7)

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l))**(10**9+5))%(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)) :
                if j+i <= len(a)-1:
                        data.append(a[i]*a[j+i] % (10**9+7))

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