Problem:


Score : 300 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).

Constraints

2 \leq N \leq 2\times 10^5

0 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

11

We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11.

Sample Input 2

4
141421356 17320508 22360679 244949

Sample Output 2

437235829



Sample input:
3
1 2 3


Sample output:
11

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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:]
  for j in nokori:
    res += (a * j) % (10 ** 9 + 7)
print(res % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7

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

# print(n, a)

res = 0

for i in range(0, n-1):
    for j in range(i+1, n):
        # print(a[i], a[j], a[i]*a[j])
        res += a[i]*a[j]
   
print(res%MOD)

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

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

Submission status: Time Limit Exceeded

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

num = int(input())
an = list(map(int, input().split()))

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
N = int(input())
add = 0
Z = list(map(int, input().split()))

com = combinations(Z,2)
for i , z in com:
  add = add + i*z
res = add%(10**9+7)
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
sum_L = []

for i in range(1,len(L)):
    sum_L.append(sum(L[i:]))

ans = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    number = int(input())
    num_list = list(map(int, input().split()))
    total = sum([num_list[i]*num_list [j]for i in range(number) for j in range(i+1, number)])
    div = total // (10**9 + 7)
    print(total - div * (10**9 + 7))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

size = len(ls)

ans = 0
for i in range(size - 1):
  for j in range(i+1, size):
    tmp = (ls[i] * ls[j])
    ans = ans + tmp


print(ans%1000000007)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
ans = 0

for x in range(m):
  for y in range(m-x-1):
    ans += (a[x] * a[y+x+1])
print(ans % mod)

Submission status: Time Limit Exceeded

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

    M = 10 ** 9 + 7

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


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i)%(1000000000+7) for i in input().split()]
res=0
for i in range(n-1):
    for j in range(i+1,n):
        res+=(a[i]*a[j])%(1000000000+7)
print(res%(1000000000+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 = list(map(int, input().split()))
A_list.sort()
A_list.insert(0,0)
sum = 0
for i in range(1, N):
    for j in range(i + 1, N + 1):
        sum += (A_list[i] * A_list[j]) 
print(sum% 1000000007)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))

mod = 10**9+7
suma = 0
for i in range(n-1):
    tmp=np.sum(a[(i+1):])%mod
    suma+= ((a[i]*tmp))%mod
print(suma%mod)

Submission status: Time Limit Exceeded

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

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

print(ans%MOD)

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

    print(r % m)
    return

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
counter = 0
lis = []
N = int(input())
A = list(map(int, input().split()))
for pair in itertools.combinations(A, 2):
    counter += pair[0] * pair[1]
print(counter%1000000007)

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(i+1,N):
    ans+=l[i]*l[j]%1000000007
print(ans%1000000007)

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

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):
    for j in range(i+1,N):
        summation += (B[i] * B[j])
print(summation % x)

Submission status: Time Limit Exceeded

Solution code:
# abc177_c.py
# https://atcoder.jp/contests/abc177_c


# [開発時用] ログ関数
def lg(value):
    flag = False
    # flag = True
    if flag:
        print(str(value))


# [開発時用] exit処理
def xt(log):
    lg('★exit() - ' + str(log))
    exit()


# 本体
def get_results():

    # 引数処理部
    lines = list()
    # 仕様でn行と決まっている場合(の例)
    lines_count = 2
    # 先頭行のNで行数が決まる場合(の例)
    # line = input()
    # lines.append(line)
    # N = int(line)
    # lines_count = N
    for _ in range(lines_count):
        lines.append(input())

    # 演算部
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    lg(f'values=[{values}]')

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

    return [su]


# 主処理
def main():
    results = get_results()

    for result in results:
        print(result)


# 起動処理
if __name__ == '__main__':
    main()

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):
        amari = (A_list[i-1] * A_list[j-1]) % (10**9 + 7) 
        cnt += amari
        if cnt >= (10**9 + 7):
            cnt %= (10**9 + 7)
print(cnt)

Submission status: Time Limit Exceeded

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

resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():

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

    import collections

    c = collections.Counter(a).most_common()

    m = 10**9 + 7
    ans = 0
    for i in range(0,len(c)):
        num1 = c[i][0]
        cnt1 = c[i][1]
        if cnt1 != 1:
            tmp = (num1**2) % m
            ans +=  tmp * ((cnt1 * (cnt1 - 1) ) // 2)
        for j in range(i+1, len(c)):
            num2 = c[j][0]
            cnt2 = c[j][1]
            tmp = (num1 * num2) % m
            ans += tmp * (cnt1 * cnt2)

    print(ans%m)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

ans = 0
b = []
c = 0

for i in range(n-1,0,-1):
    c = c + a[i]
    b.insert(0,c)

b.insert(0,0)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
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:
N = int(input())
an = list(map(int,input().split()))

ans = []
l = 1

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

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

Submission status: Time Limit Exceeded

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

i = 0
Ans = 0
while i < N-1:
    j = i + 1
    k = 0
    while j < N:
        k += A[j]
        j += 1
    Ans += (A[i] * k)
    i += 1

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
count = 0
for i in range(n-1):
    for ii in range(i+1,n):
        count += li[i]*li[ii]%(10**9+7)
print(count%(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 i,j in itertools.combinations(A,2):
    sum += i*j
print(sum % MOD )

Submission status: Time Limit Exceeded

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

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


print(b)

Submission status: Time Limit Exceeded

Solution code:



n=input()
n=int(n)
Sum=0
m = 1000000007
arr=list(map(int,input().rstrip().split()))

i2=0
for i in range(len(arr)):
    for j in range(i+1,len(arr)):
        
        i1 = 1
        i1 = ((i1*arr[i]) % m )   
        i1 = ((i1*arr[j]) % m  ) 
        Sum=(Sum+i1)%m
        
        

print(Sum)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
num = input().split()

ass = 0

for i in range(k):
    for j in range(i+1,k):
        n1 = int(num[i])
        n2 = int(num[j])
        n3 = n1 * n2
        ass += n3
        ass = ass % (10**9 + 7)


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

Submission status: Time Limit Exceeded

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

tot = 0
for i in range(n):
    tot += l[i]*sum(l[i+1:n])
    '''
    if tot >= 10**9 + 7:
        tot %= (10**9 + 7)
    '''

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
# t, s = map(str,input().split())

n = int(input())
str_a = input().split()

a = []
for i in range(len(str_a)):
    a.append(int(str_a[i]))

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

print(total % (1000000000 + 7))

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))
mod = 10**9 + 7

n = ri()
a = rl()
ans = 0
for li in itertools.combinations(a, 2):
    a, b = li
    ans = (ans + a*b)%mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))

  ans = 0
  for a in AA:
    ans += a
  ans = ans % (10**9+7)
  ans = ans**2
  ans = ans % (10**9+7)
  for a in AA:
    ans -= a**2
    while ans<0:
      ans += 10**9+7
  ans = ans % (10**9+7)
  print(int(ans/2))
solve()

Submission status: Time Limit Exceeded

Solution code:
a = [input().split() for l in range(2)]
count = 0
N = int(a[0][0])

for i in range(N):
    for j in range(i):
        if i != j:
            count = (int(a[1][i])*int(a[1][j])+count) % 1000000007
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
INF = 10**9 + 7

def main():
    n = int(input())
    N = list(map(int,input().split()))
    ans = 0
    for i in range(n - 1):
        #print(N[i] , sum(N[i + 1:]))
        ans += (N[i] * sum(N[i + 1:])) % INF
        ans %= INF
    print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

result = 0
for i in range(len(a)):
    result += a[i] * sum(a[i+1:]) % 1000000007

print(result % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
class Solution:
    def solve(self, A):
        mod = 10 ** 9 + 7
        n = len(A)
        ans = 0
        for i in range(n):
            for j in range(i+1, n):
                ans += A[i] * A[j]
                ans %= mod

        return ans % mod


if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    B = Solution()
    print(B.solve(A))

Submission status: Time Limit Exceeded

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



sum = 0
D = set(range(N))
E = set()
for i in D:
    E.add(i)
    for j in D - E:
        sum += A[i] * A[j]

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

print(answer%1000000007)

Submission status: Time Limit Exceeded

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

sumA = [A[N-1]]
for i in range(1, N - 1):
    sumA.insert(0, sumA[0]+A[N-i-1])

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

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

Submission status: Time Limit Exceeded

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

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

print(int(ans%mod))

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
#myans_list =  [ [0 for n in range(N)] for nn in range(N) ]
#myans = 0
#for n in range(N):
#    for nn in range(N):
#        myans_list[n][nn] = A_list[n] * A_list[nn]
#for n in myans_list:
#    print(n)
myans = 0
for n in range(N-1):
    for nn in range(n+1, N):
        myans += A_list[n] * A_list[nn]
print(myans%(1000000007))

Submission status: Time Limit Exceeded

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

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
print(S % MOD)

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]

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

num = int(input())
total = 0
str = input().split(" ")
table = list(str)
table2 = [int(i) for i in table]
for i in range(num-1):
    for j in range(i+1, num):
            total += table2[i] * table2[j]
print(total % 1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# C Sum of product of pairs

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
n = input()
a = list(map(int, input().split()))
ans = 0
for i, ai in enumerate(a):
  if i == len(a)-1:
    continue
  for aj in a[i+1:]:
    ans += ((ai%MOD)*(aj%MOD))%MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(map(int, input().split()))
combi = list(itertools.combinations(A, 2))

result = 0
for c in combi:
    result += (c[0] * c[1])
    result = result % (10**9+7)

print(result)

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

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

Submission status: Time Limit Exceeded

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

def multipleSum(A, n):
    sum = 0
    for i in range(n):
        for j in range(i + 1, n):
            sum += A[i] * A[j]
    return sum%1000000007

N = int(input())
A = list(map(int,input().split()))
n = len(A)
print(multipleSum(A,n))

Submission status: Time Limit Exceeded

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

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

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
   ans=sum%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
counter = 0
lis = []
N = int(input())
A = list(map(int, input().split()))
for pair in itertools.combinations(A, 2):
    lis.append(pair)
for n in lis:
    counter += n[0] * n[1]
print(counter%1000000007)

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:]) % MOD)
    result += tmp
    result %= MOD

print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

mod = 10**9 + 7

ans=0
for i,j in itertools.combinations(l, 2):
  num=i*j
  ans+=num
  
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):
  res += a[i]*sum(a[i+1:])
print(res%mod)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(n):
    for j in range(i + 1, n):
        sum += numbers[i] * numbers[j]
        sum %= (1000000000 + 7)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
    number = int(input())
    num_list = list(map(int, input().split()))
    sum = 0
    for i in range(number):
        for j in range(i+1, number):
            sum += num_list[i]*num_list[j]
    div = sum // (10**9 + 7)
    print(sum - div * (10**9 + 7))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
#n = 4
#a = [141421356, 17320508, 22360679, 244949]
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

ans = 0
for i in itertools.combinations(a, 2):
    ans += (i[0]*i[1])
    ans %= 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(len(A)-1):
    #print(A[i+1:])
    ans += (A[i] * sum(A[i+1:]))
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = [int(num)% (10**9 + 7)  for num in input().split(" ")]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 29 20:26:17 2020

@author: wiste
"""

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

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

ans %= (10**9+7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:


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

ans = 0
for i, j in itertools.combinations(range(n), 2):
    ans += (a[i] * a[j]) % (10**9+7)

print(ans % (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 i in itertools.combinations(moded_li, 2):
    # print(i)
    ans += i[0]*i[1]
print(ans % MOD_NUMBER)

Submission status: Time Limit Exceeded

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

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] % mod) * (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(" ")))
sm = 0
for i in range(len(a)):
    for j in range(i + 1,len(a)):

        sm += (a[j] * a[i])
print(sm % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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