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

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

Submission status: Time Limit Exceeded

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

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_ += sum([num[i] * n for n in num[i+1:]]) 
print(sum_ % 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):
        ans = (ans + (A[i]*A[j]))%MOD
        
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
import itertools

def resolve():
    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=ans%MOD+(A[i]*A[j])%MOD

    print(ans)

resolve()

Submission status: Time Limit Exceeded

Solution code:
""" C
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def _pattern(N):
    if N > 1:
        pa = _pattern(N-1)
        return [[0] + p for p in pa] + [[1] + p for p in pa]
    else:
        return [[0], [1]]

def main(N, A):
    M = pow(10, 9) + 7
    result = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            result = (result + A[i] * A[j]) % M
    return result

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

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 %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(n):
  ans += sum(at[i+1:])*at[i]
print(ans % mod)

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:
        for j in range(i+1, N):
            ans += A_list[i] * A_list[j]
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:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]


import itertools

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

ans = 0
a = list(itertools.combinations(seq,2))

for i in range(len(a)):
    #print(a[i][0], a[i][1])
    ans += a[i][0] * a[i][1]

ans %= 10**9+7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
_N = int(input())
_list = list(map(int, input().split()))
_sum = 0
_excludeSum = 0
_answer = 0

for i in range(_N):
  _excludeSum += _list[i] * _list[i]
  for l in range (_N):
    _sum += _list[i] * _list[l]

_answer = (_sum - _excludeSum)/2 % ((10**9)+7)
print(int(_answer))

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

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

sum=0
for ai,aj in it.combinations(A,2):
  sum+=ai*aj

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

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])%mod
print(sum(b)%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    m = 10**9 + 7
    B =[a%m for a in A]
    ans = 0
    for i in range(N-1):
        for j in range(i+1,N):
            # print(B[i],B[j])
            # ans += (A[i]*A[j])%(10**9+7)
            ans += A[i]%m * A[j]%m
    print(ans%m)

if __name__ == '__main__':
    main()

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] % (10**9+7)) * (a[j] % (10**9+7))
print(total % (10**9+7))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0
mod = 10**9 + 7

p = list(combinations(A,2))

for i in range(len(p)):
    ans += p[i][0] * p[i][1]

print(ans%mod)

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
As = list(map(int,input().split()))
MOD = 7+10**9
print(sum([(Ai*Aj)%MOD for Ai,Aj in combinations(As,2)])%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10**9+7
ans = 0

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

Submission status: Time Limit Exceeded

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

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

cal = 10 ** 9 + 7
amount = 0
for i in range(n-1):
    for j in range(i+1, n):
        amount += lis[i] * lis[j]

print(amount % cal)

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] 
    if tot >= divisor:
      tot = tot % divisor
    
print(tot)

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

if sum < 1000000007:
    print(sum)
else:
    print(sum%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0
mod = 1000000007
for i in range(n-1) :
  for j in range(n-i-1) :
    a1 = a[i] % mod
    a2 = a[i+j+1] % mod
    sum += a1 * a2 % mod

result = sum % mod
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
while len(a) > 0:
  lena = len(a)
  ban = a.pop(0)
  ans = ans + (ban * sum(a[0:lena]))
if ans > 10 **9:
  ans = ans % (10 **9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=0
m=1000000007
for i in range(n):
  for j in range(i+1,n):
    if l[j]>0 and l[i]>0:
      s=(s+(l[i]%m*l[j]%m)%m)%m
print(s)

Submission status: Time Limit Exceeded

Solution code:
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    li.sort()
    res = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            res += li[i] * li[j]
    print(res % 1000000007)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

for i in range(N-1):
  Ai = A[i]
  AJ = A[i+1:]
  goukei += sum(AJ)*Ai
  goukei = goukei%mod

print(goukei)

Submission status: Time Limit Exceeded

Solution code:

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(0,N):
  for j in range(i+1,N):
    ans = 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()))
MOD = 1000000007
ans = 0

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

print(ans)

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]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

MOD = 10 ** 9 + 7

N = I()
A = LI()
ans = 0

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

Submission status: Time Limit Exceeded

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

result = 0
MOD = 10**9+7

for i in range(len(As)-1):
    tmp = As[i] * sum(As[i+1:])
    tmp %= MOD
    result = (result+tmp) % MOD

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
Sum_a = 0
for i in range(N):
  Sum_j = 0
  for j in range(i+1, N):
    Sum_j += alist[j]
  Sum_a += alist[i]*Sum_j
print(int(Sum_a%(1e9+7)))

Submission status: Time Limit Exceeded

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

import sys
import math
from decimal import Decimal, ROUND_DOWN
from collections import deque
from itertools import combinations
import copy

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, ) = [int(e) for e in lines[0].split(' ')]
    a = [int(e) for e in lines[1].split(' ')]


    return (n, a)


def solve(n, a):

   
    total = 0
    m = int(10**9 + 7)
    for i in range(n-1):
        for j in range(i+1, n):
            tmp = (a[i] * a[j]) % m
            total = (total + tmp) % m
            


    return total
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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])%(1000000007)
print(sumA%(1000000007))

Submission status: Time Limit Exceeded

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

goukei = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

o = 0

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from copy import deepcopy
from heapq import heappop, heappush
from bisect import bisect_left, bisect
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations

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

sum = 0
for c in combinations(A, 2):
    sum += c[0] * c[1]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

rule = 1000000007
s = 0
for i in range(len(As)):
    s += As[i] * sum(As[i+1:])
    if s >= rule:
        s = s % rule
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
MOD = 1000000007
for i in range(len(A)):
    A[i]=A[i]%MOD
import itertools
c = itertools.combinations(A, 2)
q=0
for v in c:
    q +=v[0]*v[1]%MOD
print(q%MOD)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
  n = int(input())
  a = list(map(int,(input().split())))
  c = list(itertools.combinations(a, 2))
  #print(c)
  n = 0
  for a1,a2 in c:
    n += a1*a2 
    
  print(n%(10**9+7))  
  
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

total = 0

for x in range(len(A)):
    for y in range(x+1, len(A)):
        total += A[x]*A[y]
print(total % (10**9+7))

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    
    a_sum = []
    for i in range(1, len(a)):
        a_sum.append(sum(a[:len(a)-i]))

    total = 0
    a.reverse()

    for i in range(len(a_sum)):
        total += a[i]*a_sum[i]
    
    print(total % (10**9+7))

if __name__ == '__main__':
    main()

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))
    s = 0
    for i in range(N):
        v1 = A[i]
        for v2 in A[i + 1 :]:
            s += v1 * v2
    print(s % (10 ** 9 + 7))


main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
def gmi(): return map(int, stdin.readline().strip().split())
def gms(): return map(str, stdin.readline().strip().split())
def gari(): return list(map(int, stdin.readline().strip().split()))
def gars(): return list(map(int, stdin.readline().strip().split()))
def gs(): return stdin.readline().strip()
def gls(): return list(stdin.readline())
def gi(): return int(stdin.readline())

n = gi()
ar = gari()
c = 0
ans = 0
for i in ar[:-1]:
    c += 1
    for j in ar[c:]:
        ans += i*j
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def main():
    n = int(input())
    a = map(int, input().split())
    count = 0
    al = list(itertools.combinations(a, 2))
    for i in al:
        count += i[0]*i[1]
    return count % (10**9+7)


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

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

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
for i in range(n):
    for j in range(i+1,n):
        b+=mul(a[i],a[j])
        b=b%mod


print(b)

Submission status: Time Limit Exceeded

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

tot = 0
for i,j in A_comb:
    cnt = (i*j)%(10**9+7)
    tot = (tot + cnt)%(10**9+7)
    
print(tot)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
r = list(map(int,input().split()))
_sum = 0
o = 1
p= len(r)
z =[]
for g in range(p):
    v = r[g]%(10**9+7)
    z.append(v)
y = len(z)
for i in range(y-1):
    a = z[i]
    #print("a:" +str(a))
    for j in range(y-i-1):
        b=z[i+j+1]
    #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())
l=list(map(int,input().split()))
sum=0
x=10**9 +7
for i in range(n):
    for j in range(i+1,n):
        if (i<j):
            sum+=(l[i]*l[j])
print(sum%x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import numpy as np

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


val = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        val += As[i] * As[j]
        # print(As[i], ' * ', As[j])

print(int(val % (1e9 + 7)))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

MOD = 10**9+7

# tot = sum(A)

# ans = 0

# for a in A:
#     ans += a*(tot-a)
#     ans %= MOD

# ans //= 2
# ans %= MOD

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()))
ans=0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 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]
        ans %= MOD

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

mod=10**9+7

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

if __name__ == '__main__':
    N = int(sys.stdin.readline())
    A  = list(map(lambda x: int(x), sys.stdin.readline().split()))
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += (A[i]*A[j])
            ans %= 1000000007
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def resolve(in_):
    N = int(next(in_))
    A = list(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    for a, b in itertools.combinations(A, 2):
        ans += a * b
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

print(tot)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i)  % 1000000007)
    
ans = 0 
for i in range(n - 1):
    curnum = arr[i]
    for j in range(i + 1, n):
        ans += curnum * arr[j]
        if ans >= 1000000007:
            ans = ans % 1000000007

if ans >= 1000000007:
    print(ans % 1000000007)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#from functools import lru_cache
import sys
from itertools import product,combinations
from functools import reduce,lru_cache
import heapq

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def list_t(l): return vfunc(lambda *args:args)(*l)

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())



s = rvfunc(int)(reader())
n = s[0][0]
a = s[1]

al = tuple(combinations(a, 2))
#print(al)
print(sum(vfunc(lambda ab:ab[0]*ab[1])(al))%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
#abc177_B_2_最後にあまり
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]))) #((list_tmp[i] * list_tmp[j]) )
#print(int_sum)
print(int_sum % int_divide)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/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:
        for j in range(i+1, N):
            ans += A_list[i] * A_list[j]
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 sys import stdin


def mod(val):
    res = val % (10 ** 9 + 7)
    if (res < 0):
        res += m
    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 = []
    for a in A_arr:
        A_arr_mod.append(mod(a))

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

ans=0
n=int(input())
li=list(map(int,input().split()))
for i in range(1,n):
    k=list(itertools.accumulate(li[:i]))[-1]
    ans+=k*li[i]
print(ans%(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
s = [0] * N
while i < N:
    j = i + 1
    while j < N:
        s[i] += A[j]
        j += 1
    S += (A[i] % 1000000007) * (s[i] % 1000000007)
    i += 1
print((S % 1000000007))

Submission status: Time Limit Exceeded

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

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

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