Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).

Constraints

2 \leq N \leq 2\times 10^5

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

11

We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11.

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
num_list = input().split()

mod_base = 10 ** 9 + 7

num_list = [int(x) for x in num_list]

def calc_list(i, num_list):
    return num_list[i] * sum(num_list[i+1:])

sum_num = 0

for i, num_str in enumerate(num_list):
    if i+1 > len(num_list):
        break
    sum_num += calc_list(i, num_list)
    
print(sum_num % mod_base)

Submission status: Time Limit Exceeded

Solution code:
N=int(input()) # 整数の個数
A=list(map(int,input().split(" "))) # 整数のリスト

s=0 # 整数の和

for i in range(N-1): # １つ目のインデックス
    for j in range(i+1,N): # 2つ目のインデックス
        s+=(A[i]*A[j])%(1e+9+7) # 和に足してゆく
        s=s%(1e+9+7) # 大きすぎる場合は小さく

print(int(s)) # 和を出力

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):
    x[i] %= (10**9+7)
    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())
S = list(map(int, input().split(' ')))

prod=0

law=10**9+7

for i in range(N):
  for j in range(i+1, N):
    prod=prod+((S[i]%law)*(S[j]%law))%law
    
print(prod%law)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

MOD = 1000000007

l = []
for i in range(N):
    l.append(i)

C = itertools.combinations(l, 2)

a = 0
for c in C:
    a += A[c[0]] * A[c[1]] % MOD
    a %= MOD
print(a)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007

n = int(input())
str_ary = input().split()
ary = [int(c) for c in str_ary]
# ary = []
# queue = [0 for i in range(n)]
# for i int range(n):
#   num = int(str_ary[i])
#   ary.append(num)
#   for j int range(i):
#     pre_queue = []
#     queue.append(pre_queue)

sum = 0
for diff in range(n - 1):
  for i in range(n - diff - 1):
    # print(i, i + diff + 1)
    sum += ary[i] * ary[i + diff + 1] % MOD
# for i in range(n):
#   sum = 0
#   for j in range(n - i - 1):
#     # print(i, j + i + 1)
#     sum += ary[j + i + 1]
#   result += ary[i] * sum

print(sum % MOD)

Submission status: Time Limit Exceeded

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

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 = []

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]
ans = sum(a_list) % mod

print (ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
count = 0
sum = 0
for i in range(n):
  for j in range(i+1,n):
    sum = sum + a[i] * a[j]
    count = count + 1
    if count > 10:
      sum = sum%1000000007
      count = 0
print(sum%1000000007)

Submission status: Time Limit Exceeded

Solution code:
mod_const = 1000000007
n = int(input())
a = list(map(lambda x: int(x)%mod_const, 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:
# C - Sum of product of pairs
 
n = int(input())
a = [int(x) for x in input().split()]
 
s = 0; c = 1000000007
for i in range(0,(len(a)-1)):
	for j in range((i+1),len(a)):
		s = s+a[i]*a[j]
print(s%c)

Submission status: Time Limit Exceeded

Solution code:
def mod(x):
    return x % (10 ** 9 + 7)


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

Submission status: Time Limit Exceeded

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

    m = 10 ** 9 + 7
    a = [i % m for i in a]
    sum_a = [a[i] * a[j] % m for i in range(n) for j in range(i+1, n)]
    ans = sum(sum_a) % m
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

i = 0
while i < n:
  j = i + 1
  while j < n:
    total += a_list[i] * a_list[j]
    j += 1
  i += 1
print(total % (10**9 + 7))

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()
    n = 200000
    a = [1000000000 for i in range(n)]
    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:
num = int(input())
a = list(map(int,input().split()))
a = sorted(a)
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:
import itertools

N = 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 ))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def input():
	return stdin.readline()[:-1]
N = int(input())
n = 10 ** 9 + 7
A_n = [int(i) % n for i in input().split()]
b_n = []
for i in range(N-1):
    for j in range(i+1, N, 1):
        b_n.append((A_n[i] * A_n[j]) % n)
print(sum(b_n)%n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def mo(v):
    return v % 1000000007


n = int(input())
a = 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:
import itertools

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

sum = 0

for pair in itertools.combinations(A, 2):
    # print(pair)
    sum += pair[0] * pair[1]
    if(sum >= 10**9+7):
        # sum = sum % (10**9+7)
        sum = sum - (10**9+7)

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
p,S = 0,0
for i in range(N-1):
    ap = A.pop(0)
    AA = sum(A)
    aa = ap*AA
    a = aa%1000000007
    S += a
p = S%1000000007
print(p)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
n = int(input())
lists = list(map(int, input().split()))
list_a = list()
list_b = list()
for pair in itertools.combinations(lists, 2):
    list_a.append(pair[0])
    list_b.append(pair[1])
narr_a = np.array(list_a)
narr_b = np.array(list_b)
ndot = np.dot(narr_a, narr_b)
print(ndot % (10**9 + 7))

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 = 0
  for j in range(i+1, N):
    total += A[j]
  multi = ((A[i] % mod) * (total % mod)) % mod
  answer = (answer + multi) % mod
print(str(answer))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

n = int(input())
arr = list(map(int, input().split()))
sum_arr = 0

list1 = list(product(arr, repeat = 2))

for (k, v) in list1:
    sum_arr = sum_arr + (k*v)
for value in arr:
    sum_arr = sum_arr - (value*value)
ans = int(sum_arr/2)
print(ans%1000000007)

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]
        if t > mod:
            t%=mod
        s += t
        if s > mod:
            s%=mod
print(s)

Submission status: Time Limit Exceeded

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

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:
#!/usr/bin/env python3

from itertools import combinations

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

total = sum([x * y for x, y in list(combinations(A, 2))])
result = total % (10**9 + 7)
print(result)

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 =  ans + (num[i] * num[i+j+1])

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

Submission status: Time Limit Exceeded

Solution code:
import math
N = input()
nums = [int(i) for i in input().split(' ')]

sum = 0

for i in range(len(nums)-1):
    for ii in range(len(nums)-i-1):
        sum += nums[i]*nums[i+ii+1]

sum = sum%(math.pow(10,9)+7)
print(int(sum))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
A = list(map(int, input().split()))
for i in A:
    i = i // (10**9 + 7)
    
combi = itertools.combinations(list(range(n)),2)

ans = 0

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

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 v in itertools.combinations(a, 2):
    ans += v[0]*v[1]%mod

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sum = 0

for pair in itertools.combinations(A, 2):
    # print(pair)
    sum += pair[0] * pair[1]
    if(sum >= 10**9+7):
        sum = sum % (10**9+7)

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    x = []
    for i in range(1, N):
        x.append(sum(A[i:]))

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

if __name__ == "__main__":
    resolve()

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()))
print(sum(A[i] * A[j] for i in range(N) for j in range(i+1, N)) % (1_000_000_007))

Submission status: Time Limit Exceeded

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

mod=10**9+7
sum_all=[]
for i in range(N-1):
    for j in range(i+1,N):
        sum_all.append((A[i]%mod)*(A[j]%mod))

answer=sum(sum_all)%mod
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

    for v in itertools.combinations(A, 2):
        ans += v[0] * v[1]
    print(ans % 1000000007)
main()

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = [0] * (N + 1)
    for i in range(0, N - 1):
        ai = A[0]
        aj = A[i + 1]
        ans[0] += ai * aj
    for j in range(1, N - 1):
        if A[j - 1] != 0:
            ans[j] = (ans[j - 1] - A[j - 1] * A[j]) // A[j - 1] * A[j]
        else:
            for k in range(j, N - 1):
                ai = A[k]
                aj = A[k + 1]
                ans[j] += ai * aj
    ret = 0
    for k in range(0, N):
        ret += ans[k]
    ret = ret % mod_v
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import itertools

lst = []
for v in itertools.combinations(A, 2):
    n = v[0] * v[1]
    lst.append(n)
x = sum(lst)

result = x % 1000000007
print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
W = 0
ans = 0
while len(A) > 1:
    a = A.pop(0)
    W = a * sum(A)
    ans += W
print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
AL = input().split()

import itertools
sum = 0
for pair in itertools.combinations(AL, 2):
  sum = sum + int(pair[0]) * int(pair[1])
  
print(sum % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0

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

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

Submission status: Time Limit Exceeded

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

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]
  del nums[0]

  for j in range(len(nums)):
    sum += i_a * nums[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):
        ans += a[i] * a[j]
ans %= 1000000007
print(ans)

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]
    sumpro += (a[i]* x)%mod
        
print(sumpro%mod)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
*A,=map(int,input().split())
t=10**9+7
S=[a%t for a in A]

ans=0
for i in range(N):
       ans+=S[i]*sum(S[i+1:])
print(ans%t)

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

print(sum)

Submission status: Time Limit Exceeded

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

# print(N)
# print(A_list)

ret = 0
now_sum = sum(A_list)
# print("スタート{}".format(now_sum))

for i in range(len(A_list)):
  now_sum -= A_list[i]
  multiple_base = A_list[i]
  # print('now_sumから{0}を引いて{1}'.format(A_list[i], now_sum))
  before_total = 0
  for q in range(i + 1, len(A_list)):
    before_total += A_list[q]
  # print("before_totalは{0}, multiple_baseは{1}, 掛け算で{2}".format(multiple_base, before_total, multiple_base * before_total))
  ret += multiple_base * before_total
  
print(ret % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans % (10**9+7)
  ans = ans**2
  ans = ans % (10**9+7)
  for a in AA:
    aa = (a**2) % (10**9+7)
    ans -= a**2
    while ans<0:
      ans += 10**9+7
  ans = ans % (10**9+7)
  print(int(ans/2))
solve()

Submission status: Time Limit Exceeded

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

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

print(ans % M)

Submission status: Time Limit Exceeded

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

i = 0
Ans = 0
while i < N-1:
    Ans += (A[i] * sum(A[i+1:N]))
    Ans = Ans % (10**9 + 7)
    i += 1
print(Ans)

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 = (raw + A[j]) % MOD
    else:
        raw = raw % MOD
    ans = (ans + A[i] * raw) % 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 and not i ==t]
num = np.sum(sum_list)
num = num%mod
print(num)

Submission status: Time Limit Exceeded

Solution code:
from numba import jit

def f(i, j):
  return i*j

@jit
def sigma(func, frm, to, list):
  result = 0
  for i, l in enumerate(list):
    for j in range(i+1, to):
      result += func(l, list[j])
  return result

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

mod_n = 10 ** 9 +7
print(sigma(f,0,N, A) % mod_n)

Submission status: Time Limit Exceeded

Solution code:
def get_mod(a, b, mod):
  res = 0
  while b > 0:
    b = int(b)
    if b&1:
      res = res + a
      res = res % mod
    a = a * 2
    a = a % mod
    b = b / 2
  return res

n = int(input())
ls_a = [int(x) for x in input().split()]

mod = 10 ** 9 + 7

sum_mod = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = get_mod(ls_a[i], ls_a[j], mod)
    sum_mod += tmp
    if sum_mod >= mod:
      sum_mod -= mod

print(sum_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]*a[j])%mod
    print(ans%mod)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = stdin.readline
N = int(input())
n = 10 ** 9 + 7
A_n = [int(i) % n for i in input().split()]
b_n = []
for i in range(N-1):
    for j in range(i+1, N, 1):
        b_n.append((A_n[i] * A_n[j]) % n)
print(sum(b_n)%n)

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 = []

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

ans = sum(a_list) % mod

print (ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def inputt():
    return sys.stdin.readline().strip()
def printt(n):
    sys.stdout.write(str(n)+'\n')
def listt():
    return [int(i) for i in inputt().split()]
n=int(inputt())
l=listt()
mu=0
su=0
c=1000000007

for a in range(n-1):
    for b in range(a+1,n):
        mu=( ( l[a] % c ) * ( l[b] % c ) ) % c
        su= sum(( ( su % c ), ( mu % c ) )) % c
printt(su)

Submission status: Time Limit Exceeded

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

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

    print(answer)

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 = ans + s

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

A = list(map(lambda x: x %mod,A))
for i in range(N-1):
    for j in range(i+1,N):
        ans += A[i] * A[j]
        ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

print(ans)

Submission status: Time Limit Exceeded

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


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

print(total % (1000000000+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] * sum(a[(i+1):]))

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

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
#ABC177  C
import itertools
import numpy as np
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007

l = []
for i in itertools.combinations(a, 2):
  l.append(i[0]*i[1] % mod)
ans = sum(l)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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



count = 0

b_list = a_list



for i in range(n-1):

    for k in range(len(b_list[i+1:])):
        count += a_list[i] * b_list[i+1:][k]

MOD = 1000000007
print(count % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
result = 0
i = 0
for x in A[:N]:
  for y in A[i+1:]:
    result += x * y
  i += 1

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

Submission status: Time Limit Exceeded

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

    m = 10 ** 9 + 7
    a = [i % m for i in a]
    sum_a = [a[i] * a[j] for i in range(n) for j in range(i+1, n)]
    ans = sum(sum_a)
    print(ans % m)

if __name__ == '__main__':
    main()

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

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
t=np.array(input().split(' '))
num=np.zeros(n)
for a in range(n):
  num[a]=int(t[a])
x=0
for a in range(n):
  for b in range(n-a-1):
    x+=num[a]*num[a+b+1]
if x>=10**9+7:
  x=x%((10**9)+7)
print(int(x))

Submission status: Time Limit Exceeded

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

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

# A = list(map(lambda x: x %mod,A))
for i in range(N-1):
    for j in range(i+1,N):
        ans += A[i] * A[j]
        ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0
k = 7 + 10**9


for i in range(0,n-1):
    a[i] = a[i] % k

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

sum = sum % k
print(sum)

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(2**len(A)):  # 空集合を除く場合はrange(1, 2**len(list1))
    list2 = []
    for j in range(len(A)):
        if (i >> j) &1 == 1:
            list2.append(A[j])
    if len(list2) == 2:
        ans += list2[0]*list2[1]
#        print(ans)
#    print(list2)
    ans = ans%mod
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
result = 0
for i in itertools.combinations(a, 2):
    result += i[0] * i[1]

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int, input().split()))
mod_a = [i%(10**9 + 7) for i in a]
cop = copy.deepcopy(mod_a)
res = 0
for i in cop:
  b = i
  #print(b)
  #cop[i]
  #print(mod_a)
  if len(mod_a)!=1:
  	mod_a.remove(i)
  	#mod_b = [j*b%(10**9 + 7) for j in mod_a]
  	res += (sum(mod_a)*b)%(10**9 + 7)
  	#print(res)
print(res%(10**9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# abc177_c.py
import numpy as np
from numba import njit

@njit
def solve(N,A):
    ans = 0
    mod = 10**9+7
    for i in range(N-1):
        for j in range(i+1,N):
            if i != j:
                ans+=A[i]*A[j]
                ans%=mod
    return ans%mod

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

a=int(input())

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

sum=0
mod = 10**9+7

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:
def f(i, j):
  return i*j

def sigma(func, frm, to, list):
  result = 0
  for i, l in enumerate(list):
    for j in range(i+1, to):
      result += func(l, list[j])
  return result

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

mod_n = 10 ** 9 +7
print(sigma(f,0,N, A) % mod_n)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def NextInts(): return map(int,input().split())

saisyo = input()
X = NextInts()
ANSWER = 0
MOD = 10**9+7
for i in itertools.combinations(X, 2):
	answer = (int(i[0])*int(i[1]))
	ANSWER+=answer
print(ANSWER%MOD)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

readline = sys.stdin.readline
# puorquoi le sys.stdin.buffer.readline() fonctionne plus sur atcoder?
iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
#sys.setrecursionlimit(10 ** 8)
#INF = 1 << 30
MOD = (10 ** 9) + 7


def debug(*x):
    print(*x, file=sys.stderr)


# s == self
class atcoder():
    def __init__(s):
        s.N = int(input())
        

    def çözmek(s):
       
        liste = list(map(int, input().split()))
        res = []
        res.append(s.関数(s.N, liste))
        print(*res)	
    
    def 関数(s, n, liste):
        res = 0
        for i in range(n):
            for j in range(i+1, n):
                res += liste[i] * liste[j]
                res %= MOD

        return res 

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()

Submission status: Time Limit Exceeded

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

# sum_of_power = sum(A) ** 2
# power_of_sum = sum([a ** 2 for a in A])

# ans = (sum_of_power - power_of_sum) // 2
# ans %= 1000000007

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

print(ans)