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

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

Submission status: Time Limit Exceeded

Solution code:
i1 = int(input())
i2 = input().split(" ")

s=0
t = 1 
for i in i2:
  for ii in i2[t:]:
    s += int(i)*int(ii)
  t += 1
  
print(s % ((10**9)+7))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
num_list = list(map(int, input().split(' ')))

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

print(ans)

Submission status: Time Limit Exceeded

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

def m(i):
  return i%(10**9+7)

for i in range(N):
  for j in range(i+1,N):
    r += A[i]*A[j]
  r = m(r)

print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
import itertools
for i in itertools.combinations(a_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()))
ans = 0
l = len(a)
for i in range(l):
    for j in range(l):
        if i >= j or (i+1) > n or (j+1) > n:
            continue
        ans += (a[i]*a[j]) % (10**9+7)
        ans = ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import math


def get_int_args():
    args = input().split()
    return list(map(int, args)), len(args)


def get_str_args():
    return input().split()


if __name__ == '__main__':
    n = int(input())
    a = get_int_args()[0]
    sum = 0
    for i in range(len(a) - 1):
        for j in range(i + 1, len(a)):
            sum += a[i] * a[j]
    print(sum % int(1e9 + 7))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
from collections import Counter,deque
import math
cin = stdin.readline
cout = stdout.write
def inpn():
    return(int(cin()))
def inpl():
    return(list(map(int,cin().split())))
def inps():
    return cin()[:-1]
def inpv():
    return (map(int, cin().split()))
def outs(s):
    cout(s)
def outn(n):
    cout(str(n))
def outl(l):
    for i in l:
        cout(str(i)+" ")
def outb(s):
    cout(str(s))


n = inpn()
l=inpl()
m=1000000007
add=0
for i in range(n-1):
    add+=(l[i]*sum(l[i+1:]))%m
outn(add%m)
cout("\n")

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
mod = 10**9+7

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

ans = 0

for i,j in combinations(li,2):
    ans += (i*j)
    ans = ans%mod
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

mod = 10**9 + 7
N = int(input())

A = [int(i)%mod for i in input().split()]

ans = 0
for i, j in itertools.combinations(A, 2):
    ans += (i*j)

print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def add(a, b):
    return (a + b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#N = int(input())
#C = input()
#D, T, S=map(int,input().split())
#C = []
#for i in range(N):
#    C.append(list(map(int,input().split())))
c = 0
for i in range(0,N-1):
    for j in range(i+1, N):
        c = add(c, mul(A[i], A[j]))

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
m = 1000000007
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]
print(sum%m)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
hako=list(map(int,input().split()))
fin=0
for i in range(N):
  for k in range(N):
    if i!=k:
      fin=fin+hako[i]*hako[k]
fin=fin//2
fin=fin%(10**9+7)
print(fin)

Submission status: Time Limit Exceeded

Solution code:
# C Sum of product of pairs

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
#437235829 mod(10^9+7)
sumA=0
for i in range(N-1):
  for j in range(1,N-i):
    sumA+=A[i]*A[i+j]

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

Submission status: Time Limit Exceeded

Solution code:
n= input()
a = [int(_) for _ in input().split()]
sum=0
for n in range(0,len(a)):
    for n2 in range(n+1,len(a)):
        if(a[n]*a[n2]>10**9+7):
            sum +=a[n]*a[n2]%(10**9+7)
        else:
            sum += a[n] * a[n2]
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
i = 0
j = 0
S = 0
while i < N:
    j = i + 1
    while j < N:
        S += (A[i] % 1000000007)*(A[j] % 1000000007)
        j += 1
    i += 1
print((S % 1000000007))

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):
        for j in range(i+1,len(A)):
            aa = A[i]% m
            bb = A[j]% m
            ans = aa * bb
            s += ans

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

print(ans)

Submission status: Time Limit Exceeded

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

base = int(1e9+7)
tot = 0

for i in range(N-1):
    for j in range(i+1, N):
        # print(i,j)
        tot += A[i]*A[j]
        tot %= base
print(tot)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))

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

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

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(1, N-i):
        sum_ = sum_ + A[i]*A[-j]
result = pow(sum_, 1, (10**9+7))
print(result)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
nums = input()
lst = []

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

total = 0

for i in range(num - 1):
  for j in range(i + 1, num):
    total += lst[i] * lst[j]
    
answer = total % (10**9 + 7)

print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10**9+7

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a = list(map(int,input().split()))
c = itertools.combinations(a, 2)
ini = [v[0]*v[1] for v in c]
print(sum(ini)%(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:N])
  
mod = 10**9 + 7
print(ans%mod)

Submission status: Time Limit Exceeded

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

from itertools import combinations

MOD = 10**9+7
result = 0
for seq in combinations(range(0, n), 2):
  result += a[seq[0]] * a[seq[1]] % MOD
print(result%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = []
for i in range(len(a)):
    for j in range(len(a)):
        if i < j:
            result.append(a[i] * a[j])

print(sum(result) % (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
combi = list(itertools.combinations(A, 2))

result = 0
for c in combi:
    result += (c[0] * c[1]) % mod
    result = result % mod

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int,input().split()))
ans = []
for i in range(N-1):
  product = []
  for j in range(1,N-i):
    product.append(array[i]*array[i+j])
  ans.append(sum(product))
print( sum(ans)%(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(n):
    for j in range(i+1,n):
        s+=a[i]*a[j]

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 k in range(n):
    if A[k] > 500000000 :
        A[k] = A[k] - mod

for j in range(n):
    for i in range(j):
        tmp = A[i]*A[j] % mod
        ans = ans+tmp
ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
num = input().split()

ass = 0

for i in range(k):
    for j in range(i+1,k):
        n1 = int(num[i]) % (10**9 + 7)
        n2 = int(num[j]) % (10**9 + 7)
        n3 = n1 * n2
        ass += n3
    ass = ass % (10**9 + 7)


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans%(1000000000+7))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def result(nums):
  sum = 0
  m = 1000000007
  for i, num in enumerate(nums):
    for j in range(i+1, len(nums)):
      sum += nums[i]*nums[j]
  return sum%m

if __name__ =="__main__":
  loop = int(input())
  user = [int(i) for i in input().split()]
  print(result(user))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    if i != N -1:
        ans += A_list[i] * sum(A_list[i+1:N])
while ans >= 10 ** 17 + 700000000:
    ans -= 10 ** 17 + 700000000
while ans >= 10 ** 15 + 7000000:
    ans -= 10 ** 15 + 7000000
while ans >= 10 ** 13 + 70000:
    ans -= 10 ** 13 + 70000
while ans >= 10 ** 11 + 700:
    ans -= 10 ** 11 + 700
while ans >= 10 ** 9 + 7:
    ans -= 10 ** 9 + 7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
N = int(input())
add = 0
Z = list(map(int, input().split()))
 
com = combinations(Z,2)
for i , z in com:
  add = add + i*z
res = add%(10**9+7)
print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
mod=int(1e9)+7
def SumOfProductOfAllPairArrayElement(arr):
    sum = 0
    l = len(arr)
    if l == 1: 
        return arr[0]
    for i in range(0, l):
        for j in range(i+1, l):
            sum += (arr[i]%mod * arr[j]%mod)%mod
            
    return sum%mod
 
def main():
    n=int(input())
    vals = list(map(int,input().split(" ")))
    print(SumOfProductOfAllPairArrayElement(vals))


#-----------------------------BOSS-------------------------------------!
# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
D = 10 ** 9 + 7
N = int(input())
L= list(map(int, input().split()))
  
ans = 0
C = combinations(L,2)
for c in C:
    ans += c[0] * c[1] % D
print(ans % D)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

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

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

ans = 0
for i in combi:
    ans +=i[0]*i[1]

print(np.mod(ans,10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = combinations(lst, 2)
res = 0
for i in comb:
  res += i[0] * i[1]
print(res % ((10**9)+7))

Submission status: Time Limit Exceeded

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

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

ans = ans % tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
a = list(itertools.combinations(A,2))
#print(a)
#print(a[1])
for i in range(len(a)):
    tmp = a[i]
    #print(tmp)
    ans += tmp[0]*tmp[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(1,N):
    ans += A[i-1] * sum(A[i:])
    ans = ans % 1000000007

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

## 高々 N(N-1)/2　< 2 * 10^10 のため何とかなる...?
mod = 10**9 + 7

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

ans = sum % mod
print(ans)

Submission status: Time Limit Exceeded

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

resolve()

Submission status: Time Limit Exceeded

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
#if l[i] == l[j]: continue
n = int(input())
a = list(map(int, input().split()))
sumple = a
dummy = a
ans = 0

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

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import numpy

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

ans = 0

for i in range(N-1):
  res = numpy.cumsum(A[i+1:N])
  ans += A[i]*res[-1]
  
mod = 10**9 + 7
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

a = map(lambda x: x % (10**9+7), a)

res = 0
for x in itertools.combinations(a, 2):
    res += x[0]*x[1]
    res = res % (10**9+7)

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
z = list(map(int,input().split()))
_sum = 0
y = len(z)
for i in range(y-1):
    a = z[i]
    b = sum(z[i+1:y])
    
    #print("b:"+str(b))
    _sum += (a*b)
        #print("_sum:"+str(_sum))
print(_sum % (10**9+7))

Submission status: Time Limit Exceeded

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

def m(i):
  return i%(10**9+7)

for i in range(N):
  for j in range(i+1,N):
    #print(A[i],A[j])
    r += m(A[i]*A[j])
    r = m(r)

print(r)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
n = input()
a = list(map(int, input().split()))
ans = 0
for i, ai in enumerate(a):
  if i == len(a)-1:
    continue
  sum_aj = sum(a[i+1:])
  ans += ((ai%MOD)*(sum_aj%MOD))%MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

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

n = i_in()
a = l_in(int)

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

ans %= const
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(total % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    a_list = []

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        for past_a in a_list:
            ans += a * past_a
        a_list.append(a)
    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

N = int(input())
A = list(map(int, input().split()))
MOD = int(1e9) + 7

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(' ')))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def mod(val):
    res = val % (10 ** 9 + 7)
    if (res < 0):
        res += (10 ** 9 + 7)
    return res


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr_mod = [0] * len(A_arr)
    for i, a in enumerate(A_arr):
        A_arr_mod[i] = mod(a)

    ans = 0
    for i in range(N-1):
        ans += A_arr_mod[i] * sum(A_arr_mod[i+1:])
        ans = mod(ans)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext


# input = sys.stdin.readline
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 lcm(a, b): return a * b // gcd(a, b)


sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    n = i_input()
    a = i_list()

    sum = 0
    i = 1
    for aa in a:
        if i > len(a):
            break

        for aa_ in a[i:]:
            sum += aa * aa_

        i += 1

    print(sum % MOD)


if __name__ == '__main__':
    main()

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

print(sum)