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 sys

input = sys.stdin.readline


def solve():
    MOD = 10**9+7
    N = int(input())
    A_L = [int(x) for x in input().split()]
    ans = 0
    for i, ai in enumerate(A_L):
        for j in range(i+1, N):
            aj = A_L[j]
            ans = (ans + ai * aj) % MOD

    print(ans)


solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

mod =(10**9)+7
combinations = list(itertools.combinations(num_list, 2))
sum = 0
for tuple in combinations:
    sum += tuple[0]*tuple[1]

ans = sum%mod
print(ans)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7

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

S = 0
for x in combi:
    S += A[x[0]] * A[x[1]]
print(S % mod)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
N = int(input())

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

count = 0
for i in range(len(A)):
    for j in range(i + 1, len(A)):
        count += (A[i] * A[j]) % MOD
        count %= MOD
print(count)

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
str_line = input().split(" ")
num_line = [int(n) for n in str_line]

wa = 0
for i in range(num - 1):
    for j in range(i + 1, num):
        temp = num_line[i] * num_line[j] % 1000000007
        wa += temp
        wa %= 1000000007
        
print(wa%1000000007)

Submission status: Time Limit Exceeded

Solution code:
prime=(10**9)+7
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%prime)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()

ss = sum(A)
s = 0
for i in range(len(A)):
    s = (s + sum(A[i+1:])*A[i]) % mod

print(s)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
p = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
assert 2 <= N and N <= 2*1e5
for a in A:
    assert 0 <= a and a <= 1e9
ans = 0
for i in range(len(A)):
    for j in range(i+1, len(A)):
        ans += A[i]*A[j] 
print(ans % p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

sam = 0
i = 0
while i < len(A):
  for a in A[i+1:]:
    sam += A[i] * a
  i += 1

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int, input().split()))
res = 0
for i in range(n):
    msum = 0
    if arr[i] != 0:
        for j in range(i+1, n):
            msum += arr[j]
        res += arr[i] * msum
res = res % (10**9 + 7)
print(res)

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]

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(map(int,input().split()))
#Aa=[]
#for i in A:
    #Aa.append(i%(10**9+7))
#print(Aa)
ans = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 100000
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

n = k()
a = l()

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
int_n = int(input())
list_tmp = list(map(int, input().split()))

#print(int_n, list_tmp)

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)):
    #print(i, j)
    # print(list_tmp[i] * list_tmp[j])
    int_sum = ((int_sum + (list_tmp[i] * list_tmp[j])) % int_divide) #((list_tmp[i] * list_tmp[j]) )
#print(int_sum)
print(int_sum)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
ans=0

for i in range(N-1):
  ans+=sum(A[i]*A[i+1:])
  ans%=(1e+9+7)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
Ans = 0
S = []
for j in range(N-1):
    S.append(sum(A[:N-j-1]))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

biggest = 0
humidai = 0

result = 0


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

    if result>10**9+7:
        result = result%(10**9+7)

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
def dfs(A, start):
    global ans
    if len(A) == 2:
        ans += ((A[0]*A[1])%MOD)
        return
    else:
        for i in range(start, len(a)):
            A.append(a[i])
            dfs(A, i+1)
            A.pop()

dfs([], 0)
print(ans%MOD)

Submission status: Time Limit Exceeded

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

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
str_line = input().split(" ")
num_line = [int(n) for n in str_line]

wa = 0
for i in range(num - 1):
    for j in range(i + 1, num):
        temp = num_line[i] * num_line[j] % 1000000007
        wa += temp
        
print(wa%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

i = 0
Ans = 0
while i < N:
    j = i + 1
    while j < N:
        Ans += A[i] * A[j]
        j += 1
    i += 1

Ans = Ans % (1000000000 + 7)
print(Ans)

Submission status: Time Limit Exceeded

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

bs = 10**9 + 7
sm = 0

for i, ai in enumerate(a):
    sm += (ai * sum(a[(i+1):])) % bs
    sm = sm % bs

print(sm)

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

Submission status: Time Limit Exceeded

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

ans = 0
mod = 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from itertools import combinations

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

for c in list(combinations(A, 2)):
    tmp = 1
    for e in c:
        tmp *= e
    ans += tmp % (10**9 + 7)

print(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(len(A)):
    for ii in range(i+1, len(A)):
        s += A[i] * A[ii]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

    def MII_split():
        return map(int, input().split())

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

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

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    As = LII_split()

    for a in As:
        if a > 10 ** 9 + 7:
            a %= 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
sumA = [sum(A[i+1:]) for i in range(N)]

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(a)-1):
    ans +=a[i]*(sum(a[i+1:len(a)]))
print(ans%mod)

Submission status: Time Limit Exceeded

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

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

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):
        s+=a[i]*a[j]

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

print(s)

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[j + i + 1]

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

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from collections import defaultdict, deque


def A(d, t, s):
  if t * s >= d:
    return 'Yes'
  return 'No'


def B(s, t):
  len_t = len(t)
  len_s = len(s)

  def _get_to_change(a, b):
    assert len(a) == len(b)
    to_change = 0
    for i in range(len(a)):
      if a[i] != b[i]:
        to_change += 1
    return to_change

  min_to_change = 1001
  for i in range(len_s - len_t + 1):
    to_change = _get_to_change(s[i:i + len_t], t)
    if to_change < min_to_change:
      min_to_change = to_change
  return min_to_change


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


def D(n):
  pass


def main():
  # d, t, s = map(int, input().split())
  # print(A(d, t, s))
  # s = input()
  # t = input()
  # print(B(s, t))
  n = int(input())
  a = list(map(int, input().split()))
  print(C(n, a))


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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


def func(N, As):
    ans = 0
    for i in range(N):
        ai = As[i]
        for j in range(i + 1, N):
            aj = As[j]
            ans += ai * aj
    return ans % (10 ** 9 + 7)

if __name__ == '__main__':
    N, As = read()
    print(func(N, As))

Submission status: Time Limit Exceeded

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


def main():
    import itertools

    N, *A = map(int, open(0).read().split())
    print(sum([v[0] * v[1] for v in itertools.combinations(A, 2)]) % (10 ** 9 + 7))


main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

data = input().split()

data = [int(s) for s in data]

num = 0
ans = 0

for i in range(N) :
  num += data[i]
  ans += (sum(data) - num) * data[i]

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

a=list(itertools.combinations(a, 2))

ans=0
for x,y in a:
  ans+=x*y
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
    for j in range(i,N):
        if (i != j):
            ans += (A[i] * A[j])
            ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=map(int,input().split())
m=0
from itertools import*
for i,j in combinations(a,2):
    k=i*j
    m+=k
print(m%1000000007)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    m = 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 % m
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

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

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

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

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):
  A[i] = A[i] % MOD

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

for i in range(len(ref)):
  a, b = ref[i]
  res += (a * b)
print(res % (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(i + 1, n):
        sum += a[i] * a[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] % 1000000007
        ans = ans % 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
b=input().split()
i=0
j=1
s=0
while i<(n-1):
    if j==n:
        i+=1
        j=i+1
        continue
    else:
        s=(s+(int(b[i])*int(b[j])))%(1000000007)
        j+=1
    
print(s)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
num_sum = 0

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

print(num_sum % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
s=0
for i in range(0,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:
#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(n):
  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())
aaa = list(map(int, input().split()))

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

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

print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    hoge = tuple(map(int, input().split()))
    sumn = 0
    mod = 10 ** 9 + 7
    for pair in itertools.combinations(hoge, 2):
        sumn += (pair[0] * pair[1])
        sumn %= mod
    print(sumn)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def 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 += (A[i] * A[j])
        sum = 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()))
P = 10**9+7
ans = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

MOD = 1000000007
sum = 0
for i in range(len(a) - 1):
    x = a[i]
    for j in range(i+1, len(a)):
        sum += (x * a[j]) % MOD

print(sum % MOD)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
for i in range(n):
  a[i] = a[i] % mod

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

Submission status: Time Limit Exceeded

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

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