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().rstrip()) #個数
line = input().rstrip().split(" ") #Ai
isum = 0

for i in range(N - 1):
    a = int(line[i])
    for j in range((i + 1), N):
        isum += a * int(line[j])

print(isum % (1000000007))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

am = [[0]*n for i in range(n)]
for i in range(n):
    am[i][i] = a[i]*a[i] % 1000000007
    for j in range(i+1, n):
        c = a[i]*a[j] % 1000000007
        am[i][j] = c
        am[j][i] = c

for i in range(n-1):
    if a[i] == 0:
        continue
    for j in range(i+1, n):
        ans += am[i][j]
ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
len_a = len(a)
range_a = range(len_a)
times1 = []
times2 = []

for i in range_a:
    times1 += [a[i]] * (len_a - (i + 1))
    times2 += a[i + 1 : ]

count = 0
for v1, v2 in zip(times1, times2):
    count += v1 * v2

print(count % (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):
 tasizann = 0
 for j in range (N-i-1):
  tasizann = tasizann + A[i+j+1]
  tasizann = tasizann % (10**9 + 7)
 S = A[i] * tasizann
 S = S % (10**9 + 7)
 ans = ans + S
ans = ans % (10**9 + 7)
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))

row = np.array([])
col = np.array([])
summary = 0
for i in range(0, n-1):
    for j in range(i+1, n):
        row = np.append(row, an[i])
        col =  np.append(col, an[j])
print(int(np.dot(row, col) % m))

Submission status: Time Limit Exceeded

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

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] * A[j] % mod
        total %= mod
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

b = [i % dx for i in a]

ans = 0
alist = []
for i in range(n):
    for j in range(i+1, n):
        alist.append((b[i] * b[j]) % dx)

ans = sum(alist)
ans %= dx
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        v1 = a_l[i]
        v2 = a_l[j]
        
        ans += v1 * v2
        ans = ans % (10 ** 9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

print(count %m)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

pair = list(itertools.combinations(a,2))
total = 0

for a_1, a_2 in pair:
    total += a_1 * a_2
    if total > 10**9+ 7:
        total %= 10**9+ 7

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_l = list(map(int, input().split()))
b_l = []
c_l = []
for i in range(n):
    b_l.append(a_l[i] % 1000000007)
for i in range(n):
    for j in range(i+1,n):
        c_l.append((b_l[i] * b_l[j]) % 1000000007)
ans = 0
for c in c_l:
    ans += c
print("{0}".format(ans % 1000000007))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from itertools import combinations

mod = 1000000007

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9 + 7
N = int(input())
array = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(len(A_list)):
	for j in range(i + 1, len(A_list)):
		sum += int(A_list[i]) * int(A_list[j])
print(sum % (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):
        if i != j:
            ans += ((a[i])*(a[j]))

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

Submission status: Time Limit Exceeded

Solution code:
input_m = input()
M = int(input_m)

input_n = input()
n = str(input_n)

#listS = list(n)
listN = n.split(' ')

A = []
mod = 10 ** 9 + 7
result = 0

for i in range(len(listN)):
    A.append(int(listN[i]))

for i in range(len(A) - 1):
    for j in range(1, (len(A) - i)):
        tmp = (A[i] * A[i + j])
        result += tmp
        result = result % mod


print(str(result))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n-1):
    #一つ目選ぶ
    for j in range(n-1-i):
        #二つ目選ぶ
        s+=a[i]*a[i+j+1]
print(s%1000000007)

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

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

# 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:
if __name__ == '__main__':
    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):
            sum = (sum + (a[i]*a[j])) % (10**9 + 7)
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
ans=0
cnt=0
# while True: """
for i in range(n-1):
    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())
A=list(map(int,input().split(' ')))

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

print(Asum)

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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


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

Submission status: Time Limit Exceeded

Solution code:
def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): # odd
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 # b = b / 2
    
  return ans

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
t=int(input())
mod=1000000007
a=[int(item) for item in input().split()]
sum=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        x=(a[i]*a[j])%mod
        sum=(sum+x)%mod
print(sum)

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

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

main()

Submission status: Time Limit Exceeded

Solution code:


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

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

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]

print(sum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())

num = input().split()

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()
    ans = 0
    for i in range(n-1):
        ans += a[i]*(sum(a[i+1:]))
    print(ans%(10**9+7))



if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(sum % mod)

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

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

print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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(N-1):
  s += (A[i] * sum(A[i+1:]))%M
print(s%M)

Submission status: Time Limit Exceeded

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

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


print(mod_answer)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    n = int(input())
    A = [int(x) for x in stdin.readline().rstrip().split()]

    m = 10 ** 9 + 7
    s = 0
    for i in range(len(A)-1):
        b_sum = sum(A[i+1:]) % m
        ans = A[i] * b_sum % m
        s += ans

    s = s % m
    print(s)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A_list = [int(_) for _ in input().split()]

ans = 0
for i in range(len(A_list)):
    if i <= N-1:
        if A_list[i] == 0:
            continue
        j = i+1
        ans += sum(map(lambda x:x*A_list[i]%(10**9+7), A_list[j:N]))
        ans = ans%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

mod=10**9+7

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

Submission status: Time Limit Exceeded

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

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


print(count%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

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



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

print(total%MOD)

Submission status: Time Limit Exceeded

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

import copy
ans = 0

for i in range(N-1):
    B = copy.copy(A)
    del B[:i+1]
    B = list(map(lambda x: x % MOD, B))
    B = sum(B) % MOD
    ans += A[i] * B
    ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

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

L = len(A)
total = 0

mod = 10**9+7

for x in range(L):
    tmp = 0
    for y in range(x+1, L):
        tmp += A[y]
    total += tmp*A[x]
print(total % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

MOD = 1000000007
ans = 0

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

print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    As = list(map(int, input().split()))

    sum_ = 0
    for i in range(N - 1):
        js = sum(As[i + 1:]) % (10 ** 9 + 7)
        sum_ += (As[i] * js) % (10 ** 9 + 7)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans = 0
dx = 10 ** 9 + 7
alist = []
for i in range(n):
    for j in range(i+1, n):
        alist.append((a[i] * a[j]) % dx)

ans = sum(alist)
ans %= dx
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9 + 7
N = int(input())
array = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

Submission status: Time Limit Exceeded

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

a.sort()

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

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:
n = int(input())
a = list(map(int, input().split()))
ans = 0

am = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        am[i][j] = a[i]*a[j] % 1000000007

for i in range(n-1):
    if a[i] == 0:
        continue
    for j in range(i+1, n):
        ans += am[i][j]
ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

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


mod=1000000007
ans=0
cnt=1

for getA in A:
    for i in range(cnt,len(A)):
        ans=ans+getA*A[i]
    cnt+=1

ans = ans%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations, product
import numpy as np

N = int(input())
A = list(map(int, input().split()))
# S = np.array(list(combinations(A,2)))
M = 10**9 + 7
cnt = 0
for i in range(N):
    cnt += A[i] * sum(A[i+1:])
print(cnt%M)

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]*A[j]%mod
        total%=mod
print(total)

Submission status: Time Limit Exceeded

Solution code:
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:
input_m = input()
M = int(input_m)

input_n = input()
n = str(input_n)

#listS = list(n)
listN = n.split(' ')

A = []
mod = 10 ** 9 + 7
result = 0

for i in range(len(listN)):
    A.append(int(listN[i]))

for i in range(len(A) - 1):
    for j in range(1, (len(A) - i)):
        tmp = (A[i] * A[i + j])
        result += tmp

result = result % mod


print(str(result))

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

sum_result = 0

for i in range(N - 1):
    Ai = An[i]
    An_ = An[i + 1:]
    sum_result += (Ai * sum(An_)) % mod


print(sum_result % mod)

Submission status: Time Limit Exceeded

Solution code:
n,a,sm = int(input()),input().split(" "),0
sm += sum([sum([int(x) * int(a[i]) for x in a[i + 1:]]) for i in range(n)])

print(sm % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
#abc177_C_5_あまりの計算を挟むのは、その計算の対象になるときだけ
int_n = int(input())
list_tmp = list(map(int, input().split()))

int_sum = 0
int_divide = (10**9) + 7
 
for i in range(0, len(list_tmp) - 1):
  for j in range(i + 1, len(list_tmp)):
    if list_tmp[i] >= int_divide:
      list_tmp_i = list_tmp[i]%int_divide
    else:
      list_tmp_i = list_tmp[i]
      
    if list_tmp[j] >= int_divide:
      list_tmp_j = list_tmp[j]%int_divide
    else:
      list_tmp_j = list_tmp[j]    
    
    int_sum = int_sum + (list_tmp_i*list_tmp_j)
    
    if int_sum >= int_divide:
      int_sum = int_sum%int_divide
      
print(int_sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

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

for i in range(1,N):
    n = A[i]*sum(A[:i])
    l.append(n)

ans = sum(l)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

ans = 0

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

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):
  for j in range(N):
    total += A[i]*A[j]
for k in range(N):
  total -= A[k]*A[k]
total = total/2
print(int(total%(10**9+7)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from cython import longlong
from itertools import combinations
N: longlong
A: longlong
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)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(result%1000000007)

Submission status: Time Limit Exceeded

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

n = int(input())
a = readInt()

# print(n)
# print(a)
l = []
ans = 0
for i in a:
    i %= 10**9+7 
# print(a)

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

ans = sum(l) % (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 += A[i]*A[j]

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

Submission status: Time Limit Exceeded

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

a=int(input())

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

sum=0

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

if __name__ == "__main__":

    n = int(input())
    y = list(input().split())

    # print(y)
    x = [int(x) for x in y]
    # n = 4
    # x = [141421356 ,17320508 ,22360679 ,244949]

    mod = pow(10,9) + 7
    # print(n)
    # print(x)
    test1 = list(itertools.combinations(x,2))


    test2 = 0
    for el in test1:
        test3 = el[0]
        for i in range(1, len(el)):
            test3 *= el[i]
        test2 += test3

    print(test2%mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy
N = int(input())
Alist = numpy.array(list(map(int,input().split())))
MOD = 1000000007
ans = 0

for i in range(N):
    ans += sum(Alist[i] * Alist[i+1:])

print(ans%MOD)

Submission status: Time Limit Exceeded

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

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(n-1-i):
        hoge = a[i]*a[i+1+j] % 1000000007
        ans = ans + hoge
        if ans >= 1000000007:
            ans = ans - 1000000007

print(ans)

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:
N = int(input())
A_n = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0

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

print(ans % mod)