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

import copy
ans = 0

for i in range(N-1):
    B = copy.copy(A)
    del B[:i+1]
    ans += A[i] * sum(B)
    ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
input();ans=0
for i in combinations(map(int,input().split()),2):
	ans+=i[0]*i[1]
print(ans%1000000007)

Submission status: Time Limit Exceeded

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

        
print(sum%mol)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

pair = list(itertools.combinations(a,2))
total = 0

for a_1, a_2 in pair:
    total += a_1 * a_2
    if total > 10**9+ 7:
        total -= 10**9+ 7

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

Submission status: Time Limit Exceeded

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


for i in range(len(a)):
    for j in range(len(a)):
        if i < j:
            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(' ')))

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

Submission status: Time Limit Exceeded

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

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

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

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

s %= (10**9 + 7)

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
An = [int(i) for i in input().split()]

mod = int(math.pow(10, 9) + 7)

sum = 0
for i in range(N - 1):
    Ai = An[i]
    for j in range(i + 1, N):
        Aj = An[j]
        sum += (Ai * Aj) % mod


print(sum % mod)

Submission status: Time Limit Exceeded

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


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

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

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n=int(input())
a=[int(_) for _ in input().split()]
l=combinations(a,2)
l=list(l)
s=0
for i in l:
    s+=i[0]*i[1]
print(s%1000000007)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

total = 0

for i in range(0,n-1):
    for x in range(i+1,n):
        seki = list1[i] * list1[x]
        total += seki

mod = 1000000007

kotae = total % mod

print(kotae)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


total=0

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_n = [int(i)%(10**9 + 7) for i in input().split()]
A_n_mod = [A_n[i] * A_n[j] for i in range(N-1) for j in range(i+1, N, 1)]
res = sum(A_n_mod) % (10**9 +7)
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
MOD = 1000000007
a_list=[int(i)%MOD for i in input().split()]


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


print(sum%MOD)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    numbers = int(input())
    number_list = list(map(int, input().split()))
    answer = 0
    for i in range(numbers - 1):
        num1 = number_list[i]
        for j in range(numbers-i-1):
            answer += num1*number_list[i+j+1]
    print(answer%1000000007)
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

m = 10 ** 9 + 7
def main():
    r = 0
    for i in range(int(n / 2)):
        r += ((a[i] % m) * (sum(a[i+1:]) % m))
    
    for i in range(int(n / 2), n-1):
        r += ((a[i] % m) * (sum(a[i+1:]) % m))
    print(r % m)
    return

main()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
c = 0
for i,j in itertools.combinations(a,2):
    x = i*j
    if x> 10**9+7:
        x = (i*j)%(10**9+7)
    c+=x
if c > 10**9+7:
    print(c%(10**9+7))
else:
    print(c)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007

n = int(input())
str_ary = input().split()
ary = [int(c) for c in str_ary]

sum = 0
num = len(ary)
for diff in range(num - 1):
  for i in range(num - diff - 1):
    # print(i, i + diff + 1)
    sum += ary[i] * ary[i + diff + 1]

print(sum % MOD)

Submission status: Time Limit Exceeded

Solution code:

"""import re
S=input()
T=input()
kai=int((1+len(T))*len(T)/2)
start=0
mozilen=len(T)
han=len(T)
kot=99999999999999
for a in range(kai):
    print(mozilen,han,start)
    if re.search(T[start:mozilen-1],S):
        if kot>len(T)-mozilen:
            kot=len(T)-mozilen
    elif start+mozilen==len(T):
        start=0
        han-=1
        mozilen=han
    else:
        start+=1

print(kot)
"""
import itertools
N=input()
A=list(map(int,input().split()))
gou=0
for a in itertools.combinations(A,2):
    if a[0]*a[1]>10**9+7:
        gou+=(a[0]*a[1])%(10**9+7)
    else:
        gou+=a[0]*a[1]
        gou=gou%(10**9+7)

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase
from itertools import combinations

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    pass


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

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

# endregion

if __name__ == "__main__":
    main()
    n = int(input())
    summ = 0
    #n , m, p = map(int, input().split())
    lst = list(map(int, input().split()))
    data = list(combinations(lst, 2))
    for i in data:
        k = i[0] * i[1]
        summ += k
    print(summ % ((10 ** 9) + 7))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = combinations(a, 2)
res = 0
for i, j in comb:
  res += i*j
print(res%(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-1):
  for j in range(i+1,N):
    ans += A[i]*A[j]
    ans = ans%mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = list(map(lambda x: int(x) % mod, input().split(" ")))

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

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

Submission status: Time Limit Exceeded

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

        if i == 0:
            continue
        # for j in range(i + 1, n + 1):
        # for _, a_j in enumerate(a_n[i + 1:], i):
        for a_j in a_n[i + 1:]:
            sum_ += (a_i * a_j) % (10E08 + 7)
    print(int(sum_ % (10E08 + 7)))
resolve()

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] % 1000000007) * (A[j] % 1000000007)) % 1000000007
print(total % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())

MOD = 1000000007

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

Submission status: Time Limit Exceeded

Solution code:
d = 10 ** 9 + 7
n = int(input())
lista = [int(x) for x in input().split()]
for k in lista:
    k %= d

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

Submission status: Time Limit Exceeded

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


def mod10_9_7(num):
    return num % (10**9+7)


ans = 0
for i in range(N-1):
    for j in range(i, (N)):
        if i != j:
            ii = A[i]
            jj = A[j]
            if ii > 10 ** 5 or jj > 10 ** 5:
                ii = mod10_9_7(ii)
                jj = mod10_9_7(jj)
            ans += ii*jj

print(mod10_9_7(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    keisu[i] += sum(a[:i])


for i in range(n):
    ans += (a[i] * keisu[i])%(1000000000+7)

        
        

print(ans%(1000000000+7))

Submission status: Time Limit Exceeded

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

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):
        # print("i,j=",i,j)
        # print(A[i], A[j])
        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()))
aij = 0
for i in range(n - 1):
    aij_pre = 0
    for j in range(i + 1, n):
        aij_pre += a[j] % (10**9 + 7)
    aij += ((a[i] % (10**9 + 7)) * aij_pre) % (10**9 + 7)
print(aij % (10**9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum_ans = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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:
N = int(input())
A = [0] * N
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()))
moder = 10**9 + 7
sumA = 0

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

print( sumA % moder )

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
s = 0
for j in range(1, n):
    for i in range(0, j):
        if a[i] >= 10**9 +7:
            a[i] -= (10**9 +7)
        if a[j] >= 10**9 +7:
            a[j] -= (10**9 +7)
        if a[i] * a[j] >= 10**9 +7:
            s += a[i] * a[j] % (10**9 + 7)
        else:
            s += a[i] * a[j]
        if s >= 10**9 +7:
            s = s % (10**9 + 7)
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    ans = num % 1000000007
    print(ans)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
l = 1

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

mad = (10**9 + 7)
if ans >= mad:
    print(ans % mad)
if ans < mad:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())

num = input()
num = num.split()
 
for i in range(s):
    num[i] = int(num[i])

ans = []
count = 0
while count != s-1:
    k = num[0]
    for j in range(s - count -1):
        ans.append( k * num[j+1])
    del num[0]
    count = count +1

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-1):
    for j in range(n):
        if j > i:
          ans += l[i] * l[j]

ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
total = 0
for i in range(N):
  for k in range(N):
    if i!=k and i<k:
      total+=A[i]*A[k]
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):
    a = A[0]
    del A[0]
    Agoukei = sum(A)
    goukei = goukei + a*Agoukei

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

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] 
        ans %= p
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import *
N = int(input())
A = list(map(int,input().split()))
ans = 0
a = combinations(range(N),2)
for i in a:
    ans += A[i[0]] * 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

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

Submission status: Time Limit Exceeded

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

import itertools

total = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a =[int(x) for x in input().split()]
ans = 0
ans2 = 0
b = 10**9 + 7
for index,i in enumerate(a):
    for j in a[index+1:]:
        ans =  (ans + (i *j)%b)%b
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):
    s += a[i]*sum(a[i+1:n])
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
strn = input()
n = int(strn)
stra = input().split()

a = []
for i in range(n):
  a.append(int(stra[i]))

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




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

Submission status: Time Limit Exceeded

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

mod = 1000000007

sum = 0
#普通にとく
for v in itertools.combinations(a, 2):
    sum += v[0]*v[1]


print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
n_list = [int(i) for i in input().split()]
ans = 0
mod = 10 ** 9 + 7
num_list = [n % mod for n in n_list]

# while len(num_list) > 1:
#     x = num_list[0]
#     num_list.remove(x)
#     ans += (x * (sum(num_list) % mod)) % mod

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

Submission status: Time Limit Exceeded

Solution code:

def main():
    from sys import stdin

    readline = stdin.readline

    N = int(readline().rstrip())
    A = readline().rstrip().split()

    total =  0

    for i in range(N):
        An = int(A.pop())
        for j in A:
            Am = int(j)
            total = total + (An * Am)

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

main()

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):
    f = 0
    for j in range(i+1, len(a)):
        f += a[j]
        f = f%(10**9+7)
    x += a[i]*f
    x = x%(10**9+7)
print(x%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import jit
@jit


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    l = np.array(l)

    tot = 0
    for i in range(n):
        tot += (l[i] * (np.sum(l[i + 1:n], dtype='int64') % (10 ** 9 + 7))) % (10 ** 9 + 7)

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

print(total % (1000000007))

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)
out = 0
for i in (al):
    out = (out + i[0]*i[1])%(10**9+7)
print(out)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

sum=0
for i in range(len(c)):
    sum+=c[i][0]*c[i][1]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
A = [int(n) for n in input().split()]
print(sum([i*j for i,j in combinations(A, 2)])%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    if a[i] == 0:
        continue
    c = 0
    for j in range(i+1, n):
        c += a[j]
    ans += a[i] * c
ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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