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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
    a.remove(0)
mod=10**9+7
b=list(itertools.combinations(a,2))

ans=0
ans=[b[i][0]*b[i][1] for i in range(len(b))]
ans=sum(ans)
ans=ans%mod
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
s = 0

def mod(x):
    return int(x % (1e+9 + 7))
 
for i in range(N):
    for j in range(N):
        if i<j:
            ans += A[i] * A[j]
print(mod(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A = [int(x) for x in input().split()]
S=[]
for i in range(N):
    s=sum(A[i+1:])*A[i]
    S.append(s)
print(sum(S)%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7
sum = 0

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

sum %= mod
print(sum)

Submission status: Time Limit Exceeded

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

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

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

total =  0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

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

ans = 0

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

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a = [int(each) for each in input().split()]

result = 0

for a, b in itertools.combinations(a, 2):
    result += a*b % 1000000007
print(result % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from itertools import combinations


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


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

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


ans = 0
for v1, v2 in itertools.combinations(a_l, 2):
    ans += v1 * v2
    ans = ans % (10 ** 9 + 7)
    
print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[]
b=0
for i in range(len(A)-1):
    for j in range(len(A)-i-1):
        a=A[i]*A[i+j+1]
        if a<(10**9+7):
            
        
            B.append(a)
        else:
            c=a%(10**9+7)
            B.append(c)
        b+=B[-1]

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

Submission status: Time Limit Exceeded

Solution code:

import itertools


N = int(input())
li = list(map(int, input().split()))
MOD_NUMBER = 10**9+7
moded_li = []
for i in li:
    ans = i % MOD_NUMBER
    if ans != 0:
        moded_li.append(ans)
ans = 0
for idx in range(len(moded_li)-1):
    ans += moded_li[idx] * sum(moded_li[idx+1:])

print(ans % MOD_NUMBER)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 177
# C - Sum of product of pairs

from itertools import combinations

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

mod=10**9+7

ans=0

for v in combinations(ls,2):
    ans+= (v[0]*v[1])%mod
    ans%=mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
t = [];s = 0
for i in range(N):
    for j in range(N):
        if i != j:
            t.append(a[i]*a[j])
for i in t:
    s += i
s = s//2
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

    mod = 10**9 + 7
    answer = 0

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
x=pow(10,9)+7

s=0

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

for i in range(n-1):
  c=i+1
  while(c<n):
    p=l[i]*l[c]
    s+=p
    c+=1
print(s%x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sigma = 0
for i in range(len(a)-1):
  start = a[i]
  after = sum(a[i+1:])
  sigma = sigma + start * after
  if sigma >= (10**9 + 7):
    sigma = sigma % (10**9+7)

print(sigma)

Submission status: Time Limit Exceeded

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

    M = 10 ** 9 + 7

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


main()

Submission status: Time Limit Exceeded

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


def listExcludedIndices(data, indices=[]):
  return [x for i, x in enumerate(data) if i not in indices]

for i in range(len(a)):
  for j in range(i, len(a) - 1):
      jData = listExcludedIndices(a, [i])
      #result.append([a[i], jData[j]])
      ans += a[i] * jData[j]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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(A)-1):
    for j in range(i+1, len(A)):
        # ans += p[i][0] * p[i][1]
        #print(A[i], A[j])
        ans += A[i] * A[j]

print(ans%mod)

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):
    a = S[i] % divisor
    b = S[j] % divisor
    tot += (a*b % divisor)
    if tot >= divisor:
      tot = tot % divisor
    
print(tot)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

a = z % 1000000007
print(a)

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):
    amount += lis[i] * sum(lis[i+1:])
print(amount % cal)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

com_A = [x * y % (10**9 + 7) for x,y in combinations(A,2)]
print(sum(com_A) % (10**9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def main():
  N = int(input())
  As = list(map(int, input().split()))
  w = 0

  c = combinations(As,2)
  for i in c:
    il = list(i)
    w = w + (il[0] * il[1])
  print(w % 1000000007)

main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def ProgramC():
    
    num = int(input())
    
    data = list(map(int,input().split()))

    count = 0

    for i in range(num-1):
        
        for j in range(i+1,num):
            
            count = count + data[i]*data[j]

    print(count%(pow(10,9)+7))

if __name__ == '__main__':
    ProgramC()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans=T%L
print(ans)

Submission status: Time Limit Exceeded

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

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


print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
a_list = input().split(" ")

b = [int(a) for a in a_list]
max = 10**9 + 7

sum = 0
for i in range(0, len(b)-1):
  for j in range(i+1, len(b)):
    sum += b[i] * b[j]
    while sum >= max:
      sum -= max
print(sum)

Submission status: Time Limit Exceeded

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

    mod_value = 10**9 + 7
    sum_ = 0
    for i in range(len(A)-1):
        sum_ = sum_ + A[i]*sum(A[i+1:])
    print(sum_ % mod_value)
main()

Submission status: Time Limit Exceeded

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

res = 0

for i in range(len(A)):
  a = A[i]
  nokori = A[i+1:]
  sums = sum(nokori)
  res += ((a * sums) % (10 ** 9 + 7))
print(res % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
from typing import List
import sys
import itertools


def solution(inp: List) -> int:
    inp = list(map(int, inp))
    ans: int = 0
    inp.pop(0)
    arr = itertools.combinations(inp, 2)
    for n, i in arr:
        ans += n * i
    q, mod = divmod(ans, 1000000007)
    return mod


inp: List = []
for j in sys.stdin:
    inp += j.split()
print(solution(inp))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AA = map(int,input().split())
AAA = list(AA)
K = len(AAA)
X =1000000007
total = 0
for i in range(K):
  for j in range(i+1,K):
    
    ans = AAA[i]*AAA[j]
    total += ans
print(total%X)

Submission status: Time Limit Exceeded

Solution code:
# import itertools

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

MOD = 10 ** 9 + 7
S = 0
# for c in list(itertools.combinations(As, 2)):
#     S += c[0] * c[1] % MOD
for i in range(N):
    for k in range(i+1, N):
        S += As[i] * As[k] % MOD
print(S % MOD)

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]
    newcur = 0 
    for j in range(i + 1, n):
        newcur += arr[j]
    newcur  = newcur % 1000000007
    ans += curnum * newcur
    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()))
c = 0
for i in range(N-1):
    for j in range(i+1,N):
        c += (A[i] * A[j]) %(10**9+7)
print(c%(10**9+7))

Submission status: Time Limit Exceeded

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

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

print (ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

N = int(input())
h = list(map(int, input().split()))
h2 = copy.copy(h)
ans = 0
for i in range(N):
    h2.remove(h[i])
    ans += h[i] * np.sum(h2)
    ans = ans % (10 ** 9 + 7)
print(int(ans))

Submission status: Time Limit Exceeded

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

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]
  if b>=10**9:
    b=b%(10**9+7)
print(b)

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 += A[j]
    ans = (ans + A[i] * sumtemp) % m0
print(ans)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(s) for s in input().split()]
mod = 10**9+7

seki_list = []
for i in range(N-1):
    seki = sum(A[i+1:])
    seki_list.append(seki)

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
  j=i+1
  while j<n:
    ans += (a[i]%1000000007)*(a[j]%1000000007)%1000000007
    ans = ans%1000000007
    j+=1
    
print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

total = (tmp*tmp-tmp2)/2

while(total > 1000000007):
    total -= 1000000007

print(int(total))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
sum = 0

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

#print(a)
di = 10**9+7

s = 0
for i in range(N):
    for j in range(i+1,N):
        #print(a[i],a[j])
        s = (s + (a[i]*a[j])%di)%di
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

total = 0

for i in range(len(a_list)):
  for j in range(len(a_list) - i -1):
    # print(a_list[i], a_list[-j-1])
    total += a_list[i] * a_list[-j-1]

print(total % (1000000000+7))

Submission status: Time Limit Exceeded

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

x = 0

for i in range(0, n - 1):
    for j in range(i + 1, n):

        x += (k[i] * k[j]) % (10 ** 9 + 7)

        if x < 10 ** 9 + 7:
            continue
        else:
            x = x % (10 ** 9 + 7)

print(x)

Submission status: Time Limit Exceeded

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

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

print(total % (1000000000+7))

Submission status: Time Limit Exceeded

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

mod = 1000000007

comb=list(itertools.combinations(a,2))
ans=0
for i in comb:
    ans+=(i[0]*i[1])%mod
print(ans%mod)

Submission status: Time Limit Exceeded

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

o = []

for i in range(0, n-1):
    num1 = a[i]
    for j in range(i+1, n):
        num2 = a[j]
        o.append(num1*num2)
o = sum(o)

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

Submission status: Time Limit Exceeded

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

Sum = 0
for i in range(n-1):
    for j in range(i+1, n):
        Sum += a[i] * a[j]
print(Sum % (int(1e9)+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b = list(map(int, input().split()))
b.sort()
S=0

for i in range(0,a):
    S=S+b[i]*sum(b[i+1:a])
print(S % (10**9+7))

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

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


if __name__ == '__main__':
    main()

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
SUM = sum(A_list)
for i in range(N):
    SUM -= A_list[i]
    if i != N -1:
        ans += A_list[i] * SUM
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:
import itertools

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

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

ans = 0
for i, j in C:
    ans += i * j
    ans = ans % (1e9 + 7)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
#ABC177  C
import itertools
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007

sum = 0
for i in itertools.combinations(a, 2):
  sum += i[0]*i[1]
ans = sum % mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

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

Submission status: Time Limit Exceeded

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

answer = 0

for i in range(N-1):
  for j in range(N-i-1):
    answer += A[i]*A[i+j+1]
    if(answer >= 1000000007):
      answer = answer % 1000000007

print(answer%1000000007)

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

Submission status: Time Limit Exceeded

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

L = len(A)
total = 0
mod = 10**9+7

for x in range(L):
    for y in range(x+1, L):
        total += A[x]*A[y]
print(total % mod)

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
ans = 0
for i in range(n):
    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()))

res = 0

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

Submission status: Time Limit Exceeded

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

out = 0
for i in range(n - 1):
    for j in range(n - i - 1):
        k = i + j + 1
        # print(A[i], A[k])
        out += ((A[i] % mod) * (A[k] % mod))
        out %= mod
print(out)

Submission status: Time Limit Exceeded

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

P=1000000007

z=0
for i in range(0,N-1):
    for j in range(i+1,N):
        p=A[i]*A[j]
#        print(i,j,p)
        z+=p

z%=P
print(z)

Submission status: Time Limit Exceeded

Solution code:
def main():

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans%p)

Submission status: Time Limit Exceeded

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