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:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def main(N, A):
    ans = 0
    for Ai, Aj in combinations(A, 2):
        ans += Ai*Aj
        ans = ans % (10**9 + 7)
    return ans

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    ans = main(N, A)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main(N, A):
    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)
    return ans

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    ans = main(N, A)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int,input().split()))
num_sum = 0
tmp_sum = 0

for i in range(N):
    for j in range(N-i-1):
        tmp_sum += array[i+1+j]
    num_sum += tmp_sum*array[i]
    tmp_sum = 0
print(num_sum%1000000007)

Submission status: Time Limit Exceeded

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

result= 0

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
sumlist = []
for i in range(1,n):
  sumlist.append(sum(a[i:n]))

result= 0

for j in range(0,len(sumlist)):
  result += a[j]*sumlist[j]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
a = len(A)
sa = sorted(A)
su = 0
for i in range(a):
    for j in range(a):
        if i<j:
            su += A[i]*A[j]

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
a = len(A)
sa = sorted(A)
su = 0
for i in range(a):
        su += sa[i]*sum(sa[i+1:])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
a = len(A)
su = 0
for i in range(a):
    for j in range(i+1,a):
        su += A[i]*A[j]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = 0
MOD = 10**9 + 7
rea = [num%MOD for num in a]
while len(rea) != 1:
    firstnum = rea.pop()
    for i in rea:
        b = firstnum * i
        s += b
s %= MOD
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = 0
MOD = 10**9 + 7
while len(a) != 1:
    firstnum = a.pop()
    for i in a:
        b = (firstnum * i)%MOD
        s += b
s %= MOD
print(s)

Submission status: Time Limit Exceeded

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

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())
num_list =  [int(i) for i in input().split()]
sum = 0
mod = 10 ** 9 + 7
for s in range(N):
    e = s + 1
    while e < N:
        result = num_list[s] * num_list[e]
        #print(str(result) + " = " + str(num[s]) + "*" + str(num[e]))
        sum += result % mod
        e += 1
print(sum % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num_list =  [int(i) for i in input().split()]
sum = 0
for s in range(N):
    e = s + 1
    while e < N:
        result = num_list[s] * num_list[e]
        #print(str(result) + " = " + str(num[s]) + "*" + str(num[e]))
        sum += result
        e += 1
mod = 10 ** 9 + 7
print(sum % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num = []
line = input().split()
for i in range(N):
    num.append(int(line[i]))

sum = 0
for s in range(N):
    e = s + 1
    while e < N:
        result = num[s] * num[e]
        #print(str(result) + " = " + str(num[s]) + "*" + str(num[e]))
        sum += result
        e += 1
mod = 10 ** 9 + 7
print(sum % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 177 C
N = int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10**9+7
B = []
for i in range(len(A)):
    B.append(A[i]%mod)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools


# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


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

MOD = 10 ** 9 + 7

answer = 0
for idx1 in range(len(arr) - 1):
    for idx2 in range(idx1 + 1, len(arr)):
        answer = (answer + (arr[idx1] * arr[idx2])) % MOD

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools


# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


n = int(input())
arr = map(int, input().split())

MOD = 10 ** 9 + 7

answer = 0
t = itertools.combinations(arr, 2)
for i in t:
    answer = (answer + i[0] * i[1]) % MOD

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
mod = 10**9+7
ans=0
for i in range(2**N):
  cl = [False]*N
  for j in range(N):
    if ((i>>j)&1):
        cl[N-1-j] = True
  total=''
  if cl.count(True) == 2:
        for k in range(len(cl)):
            if cl[k]:
                total += A[k] + '*'
        total+='1'
  if total =='':
    pass
  else:
        ans += eval(total)

print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from itertools import islice

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

M = 10 ** 9 + 7

rslt = 0
while True:
    rslt = (rslt + sum((A[0] * a) % M for a in islice(A, 1, None))) % M
    A.popleft()
    if len(A) == 1:
        break
print(rslt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from itertools import islice

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

M = 10 ** 9 + 7

rslt = 0
while True:
    rslt = (rslt + sum(A[0] * a for a in islice(A, 1, None))) % M
    A.popleft()
    if len(A) == 1:
        break
print(rslt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def calculate(n, arr):
    mod = 1000000000 + 7
    result = 0

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

    print(result % mod)


calculate(N, ARR)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    pro = 0
    for i in range(1,n+1):
        sum = 0
        for j in range(i+1,n+1):
            sum += aList[j-1]
        pro += sum * aList[i-1]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    sum = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            sum += aList[i-1]*aList[j-1]

    out = resultSur97(sum)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Submission status: Time Limit Exceeded

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

print(sm)

Submission status: Time Limit Exceeded

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

print(sm)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    A_mod = [a % mod for a in A]
    ans = 0
    for i in range(N-1):
        sum_mod = sum(A_mod[i+1:]) % mod
        mul_mod = (A_mod[i] * sum_mod) % mod
        ans = (ans + mul_mod) % mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int, input().split()))
mod = 1e9+7
sumup = 0
for i in range(n):
    for j in range(i+1,n):
        if i<j:
            sumup += x[i]*x[j]
print(int(sumup%mod))

Submission status: Time Limit Exceeded

Solution code:
def factorial(n):
    if n == 1:
        return 1
    return n*factorial(n-1)
n = int(input())
x = list(map(int, input().split()))
mod = 1e9+7
sumup = 0
for i in range(n):
    for j in range(i+1,n):
        if i<j:
            sumup += x[i]*x[j]
print(int(sumup%mod))

Submission status: Time Limit Exceeded

Solution code:
def factorial(n):
    if n == 1:
        return 1
    return n*factorial(n-1)
n = int(input())
x = list(map(int, input().split()))
mod = 1e9+7
sumup = 0
for i in range(n):
    for j in range(n):
        if i<j:
            sumup += x[i]*x[j]
print(int(sumup%mod))

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 %= 10 ** 9 + 7

print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

modn = int(1e9 + 7)

A = np.mod(A, modn)

ruiseki = []
for i in range(len(A)-1):
    tmp_sum = sum(A[i+1:len(A)])
    ruiseki.append(tmp_sum)

ret = 0
for i in range(0, len(A)-1):
  ret += A[i] * ruiseki[i]

print(np.mod(ret, modn))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

modn = int(1e9 + 7)

A = np.mod(A, modn)

ret = 0
for i in range(0, len(A)-1):
  sub_sum = 0
  for j in range(i+1, len(A)):
    sub_sum += A[j]
  ret += np.mod(A[i] * sub_sum, modn)

print(np.mod(ret, modn))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

modn = int(1e9 + 7)

A = np.mod(A, modn)

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

print(np.mod(ret, modn))

Submission status: Time Limit Exceeded

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

modn = int(1e9 + 7)

ret = 0
for i in range(0, len(A)-1):
  for j in range(i+1, len(A)):
    ret += A[i]*A[j] % modn


print(ret % modn)

Submission status: Time Limit Exceeded

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

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

modn = int(1e9 + 7)
print(ret % modn)

Submission status: Time Limit Exceeded

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

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




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    n = int(input())
    # d,t,s = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    l = []
    for i in range(len(a)):
        l.append(i)

    c_list = list(itertools.combinations(l, 2))

    sm = 0
    for tpl in c_list:
        sm += (a[tpl[0]] * a[tpl[1]]) % (10**9+7)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = str(input())
d = n.split()

ans = 0
mod = (10 ** 9) + 7

while len(d) > 1:
    cv = int(d.pop(0))
    for i in d:
        i = int(i)
        ans += (cv * i) 
    ans = ans % mod

fans = ans % mod

print(fans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = str(input())
d = n.split()

lst = []
ans = 0
mod = (10 ** 9) + 7

for j in d:
    j = int(j)
    lst += [j]

lst1 = sorted(lst)

while len(lst1) > 1:
    cv = int(lst1.pop(0))
    for i in lst1:
        i = int(i)
        ans += (cv * i) 

fans = ans % mod

print(fans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = str(input())
d = n.split()

ans = 0
mod = (10 ** 9) + 7

while len(d) > 1:
    cv = int(d.pop(0))
    for i in d:
        i = int(i)
        ans += (cv * i) 

fans = ans % mod

print(fans)

Submission status: Time Limit Exceeded

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
n = ii()
alist = lmis()

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

print(sum % 1000000007)

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]%(10**9+7))*(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()))
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:
# coding: utf-8
# 日本語を入力できるようにするために上記一文が必要


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


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

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

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

print(ans%mod)

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 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:
import sys

N = int(sys.stdin.readline().strip())
vs = [int(a) for a in sys.stdin.readline().strip().split(" ")]

M = 1000000000 + 7

ret = 0
for j in range(N):
    for i in range(j):
        ret += vs[j] * vs[i]
        ret %= M
print(ret)

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:
n = int(input())
a = list(map(int,input().split()))
inf = 10 ** 9 + 7
total = 0

l = len(a)

for i in range(l - 1):
    for j in range(i + 1, l):
        total += ((a[i]*a[j]) % inf)

print(total % inf)

Submission status: Time Limit Exceeded

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

l = len(a)

for i in range(l - 1):
    for j in range(i + 1, l):
        a[i] %= inf
        a[j] %= inf
        total += (a[i]*a[j])

print(total % inf)

Submission status: Time Limit Exceeded

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

l = len(a)

for i in range(l - 1):
    for j in range(i + 1, l):
        a[i] %= inf
        a[j] %= inf
        total += (a[i]*a[j]) % inf

print(total % inf)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input()

a = list(map(int, A.split(" ")))

cur_ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        cur_ans += a[i]*a[j]
        
cur_ans = cur_ans % (1000000000 + 7)
print(cur_ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input()

a = list(map(int, A.split(" ")))

cur_ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        #print(str(i) + " " + str(j))
        cur_ans += a[i]*a[j]
        cur_ans = cur_ans % (1000000000 + 7)

print(cur_ans)

Submission status: Time Limit Exceeded

Solution code:
#                               #
    # author : samars_diary #
    # 13-09-2020 │ 11:36:55 #
#                               #

import sys, os.path

#if(os.path.exists('input.txt')):
    #sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    a=ii();b=lii();c=0
    for i in range(a-1):
        for j in range(i+1, a):
            c+=b[i]*b[j]
    print(c%((10**9)+7))
solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = ans % 1000000007

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
MOD = 10**9+7

N = int(input())
A = np.array(list(map(int, input().split())))
A = A % MOD

AS = [np.sum(A[:i+1])%MOD for i in range(N)]
s = 0

for i in range(len(A)-1):
  s = (A[i] * ((AS[N-1]-AS[i])) % MOD + s) % MOD
  
print(s)

Submission status: Time Limit Exceeded

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

ans = 0

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

ans = ans % a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.mod(A,a)

ans = 0

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

ans = ans % a
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
"""C."""

import sys

input = sys.stdin.readline  # noqa: A001

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

MOD_VALUE = pow(10, 9) + 7
result = 0

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

if result < MOD_VALUE:
    print(result)
else:
    print(result % MOD_VALUE)

Submission status: Time Limit Exceeded

Solution code:
"""C."""

import sys

input = sys.stdin.readline  # noqa: A001

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

MOD_VALUE = pow(10, 9) + 7
result = 0

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