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

Submission status: Time Limit Exceeded

Solution code:
n = int(input("")) - 1
a = input("").split(" ")
a = [int(b) for b in a]
i = 0
j = 0
ans = 0
while i < n:
  j = i + 1
  while j <= n:
    ans += a[i]*a[j]
    j += 1
  i += 1
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

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

res = sum % (10**9 + 7)

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    ans = 0
    for i, ai in enumerate(A):
        for j, aj in enumerate(A[i+1:]):
            ans += (ai * aj) % MOD
    
    print(ans % MOD)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n=read()
a=list(reads())
num=0
l=len(a)
for i in range(l-1):
    for j in range(i+1,l):
        num+=a[i]*a[j]
num%=10**9+7
print(num)

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

Submission status: Time Limit Exceeded

Solution code:
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
a = inl()
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().split()))

biggest = 0
humidai = 0

result = 0


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

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = [int(_) for _ in input().split()]

ans = 0
for i in range(len(A_list)):
    if i <= N-1:
        for j in range(i + 1, N):
            ans += A_list[i]*A_list[j]
            ans = ans%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
a = [x%mod for x in a]
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())
As = [int(a) for a in input().split(' ')]

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
mod=1000000007
n=int(input())
#n,k=map(int,input().split())
a=[int(i) for i in input().split()]
ans=chk=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:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        for j in range(i):
            ans += A[i]*A[j]
            if ans > 10**9+7:
                ans %= (10**9+7)
    print(ans)
resolve()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb

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

ans=0
for i in range(0,n-1):
    for j in range(i+1,n):
        ans+=A[i]*A[j]
        ans %= 10**9+7
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):
  p=a.pop()
  q=sum(a)
  ans+=p*q
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sum_val = 0
    for i in range(len(A)):
        for j in range(i + 1, len(A)):
            sum_val += (A[i] * A[j]) % (10**9 + 7)
    return sum_val % (10**9 + 7)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop, heapify
import math
import itertools as it
from collections import deque 


def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

mod = 10**9 + 7

N = inp()
A = inpl()
wa = 0
for i in range(0, N - 1):
    for j in range(i+1, N):
        wa = (wa + A[i] * A[j]) % mod
print(wa)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

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:
import math
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]

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
*A,=map(int,input().split())
t=10**9+7
S=[a%t for a in A]

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
g=0
L=list(map(int,input().split(" ")))

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = list(map(int,input().split()))
_sum = 0
y = len(p)
for i in range(y):
    a = p[i]
    #print("a:" +str(a))
    for j in range(y-i-1):
        b=p[i+j+1]
        #print("b:"+str(b))
        _sum += (a*b)
        #print("_sum:"+str(_sum))
print(_sum % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
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]
    
print(res%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
array = [int(x) for x in input().split(' ')]
s = 0
for i in range(n):
    for j in range(i+1, n):
        s += (array[i] * array[j])

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

Submission status: Time Limit Exceeded

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

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
from collections import Counter,deque
import math
cin = stdin.readline
cout = stdout.write
def inpn():
    return(int(cin()))
def inpl():
    return(list(map(int,cin().split())))
def inps():
    return cin()[:-1]
def inpv():
    return (map(int, cin().split()))
def outs(s):
    cout(s)
def outn(n):
    cout(str(n))
def outl(l):
    for i in l:
        cout(str(i)+" ")
def outb(s):
    cout(str(s))


n = inpn()
l=inpl()
m=1000000007
add=0
for i in range(n-1):
    for j in range(i+1,n):
        add+=(l[i]%m*l[j]%m)%m

outn(add%m)
cout("\n")

Submission status: Time Limit Exceeded

Solution code:
def INT():
    return int(input())

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

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

N = INT()
A = LI()
mod = 10**9 + 7
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


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

A = [a % MOD for a in A]

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))
ans = 0
for a,b in combinations(lst, 2):
    ans += a*b

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    MODULO = 10**9 + 7
    n = int(input())
    A = list(map(int, input().split()))
    total = 0
    for i in range(n):
        for j in range(i+1, n):
            total = (total + A[i] * A[j]) % MODULO
    print(total)

Submission status: Time Limit Exceeded

Solution code:
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
a = lmiinps()

ans = 0

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

ans %= (10**9+7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
mod = 10**9+7

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

ans = 0

for i,j in combinations(li,2):
    ans += (i*j)%mod
    ans = ans%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import itertools

    n = int(input())
    A = list(map(int, input().split()))
    B = itertools.combinations(A, 2)
    ans = 0
    for b in B:
        ans += b[0] * b[1]

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

resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = 0
for i in range(len(a)):
    for j in range(i, len(a)):
        if i != j:
          t += a[i]*a[j]

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

Submission status: Time Limit Exceeded

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

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

print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7
import itertools

ans = 0
Cmb = itertools.combinations(A, 2)
for cmb in Cmb:
    ans = (ans + cmb[0]*cmb[1]%MOD)%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

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

ans = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
from collections import Counter,deque
import math
cin = stdin.readline
cout = stdout.write
def inpn():
    return(int(cin()))
def inpl():
    return(list(map(int,cin().split())))
def inps():
    return cin()[:-1]
def inpv():
    return (map(int, cin().split()))
def outs(s):
    cout(s)
def outn(n):
    cout(str(n))
def outl(l):
    for i in l:
        cout(str(i)+" ")
def outb(s):
    cout(str(s))


n = inpn()
l=inpl()
m=1000000007
add=0
for i in range(n-1):
    for j in range(i+1,n):
        add+=(l[i]*l[j])
        
outn(add%m)
cout("\n")

Submission status: Time Limit Exceeded

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

m = 10 ** 9 + 7

sum = 0

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

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

Submission status: Time Limit Exceeded

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

    print(ans % MOD)




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

MOD = 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
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 = list(map(int, input().split()))

mod = 10 ** 9 + 7

res = 0
for i in range(N):
    for j in range(i+1, N):
        res += (A[i] % mod) * (A[j] % mod)

print(res % mod)

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    A[i] = A[i] % (1e9 + 7)

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

print(int(sum % (1e9 + 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])
        if total >= 10 ** 9 + 7:
            total = total % (10 ** 9 + 7)
ans = total % (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	p = 1000000007
	ans = 0
	for c in itertools.combinations(A, 2):
		ans += (c[0] * c[1]) % p
		ans = ans % p
	print(ans)

main()

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import itertools

def main():

    input = stdin.readline

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

    mod = (10 ** 9) +7

    ans = 0

    for i,j in itertools.combinations(range(N),2):
        ans = (ans +  (A[i] * A[j])) % mod

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

result = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout
from collections import Counter,deque
import math
cin = stdin.readline
cout = stdout.write
def inpn():
    return(int(cin()))
def inpl():
    return(list(map(int,cin().split())))
def inps():
    return cin()[:-1]
def inpv():
    return (map(int, cin().split()))
def outs(s):
    cout(s)
def outn(n):
    cout(str(n))
def outl(l):
    for i in l:
        cout(str(i)+" ")
def outb(s):
    cout(str(s))


n = inpn()
l=inpl()
m=1000000007
add=0
for i in range(n-1):
    for j in range(i+1,n):
        add+=(l[i]*l[j])
        add=add%m
outn(add)
cout("\n")

Submission status: Time Limit Exceeded

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

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

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:
      continue
    else:
      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()))
mod = 1000000007
s = 0
for i in range(N - 1):
  s += (A[i]*sum(A[i+1:]))%mod
print(s%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import *

n = int(input())
As = list(map(int, input().split()))
D = 10 ** 9 + 7
ans = 0

for pair in combinations(As, 2):
  ans = (ans + pair[0] * pair[1]) % D
  
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    target = LI()

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


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr  =lambda x: stdout.write(str(x))

mod=1000000007


#main code
n=ii()
arr=lii()
sol=0
for i in range(n):
    for j in range(i+1,n):
        sol+=(arr[i]*arr[j])
print(sol%mod)

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7

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

ans = 0
for x, y in combinations(arr, 2):
    ans += x * y
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C - Sum of product of pairs
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += A[i]*A[j]

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    n = int(input())
    a = list(map(int, input().split()))
    sum = 0
    mod = 1000000007
    for i in range(n-1):
        for j in range(i+1, n):
            sum += a[i]*a[j]
    print(sum%mod)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
#N=3
#A=[1,2,3]
q=deque(A)
#print(q)
ans=0
for i in range(N-1):
    ans+=q.popleft() *sum(q)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7
import itertools

ans = 0
Cmb = itertools.combinations(A, 2)
for cmb in Cmb:
    ans += cmb[0]*cmb[1]%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

s = 0

for i in range(len(ai) - 1):
    for j in range(i + 1, len(ai)):
        s += (ai[i] * ai[j])
        s %= (10 ** 9 + 7)

print(s)