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: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, AS):
    sum = 0
    sumSq = 0
    for i in range(N):
        sum += AS[i]
        sum %= MOD
        sumSq += AS[i] * AS[i]
        sumSq %= MOD

    return (sum * sum - sumSq) % MOD // 2


def main():
    # parse input
    N = int(input())
    AS = list(map(int, input().split()))
    print(solve(N, AS))


# tests
T1 = """
3
1 2 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
11
"""

T2 = """
4
141421356 17320508 22360679 244949
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
437235829
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10 ** 9 + 7

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

S = 0
for a in A:
    S += a
    S %= MOD

ans = 0

for a in A:
    t = (S - a) * a
    t %= MOD
    ans += t
    ans %= MOD

ans //= 2
ans %= MOD

print(ans)

Submission status: Wrong Answer

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

aa=sum([i**2 for i in a])

ans=((s**2-aa)/2)%mod

print(int(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
def selfmult(x):
    return x**2
dot=sum(A)**2-sum(map(selfmult,A))
print(int(dot/2%(1000000007)))

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
import random
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n - k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv


def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]


class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h + 2) * (w + 2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x

    def getgrid(self, x, y):
        return self.grid[y][x]

    def get(self, x, y):
        return self.cost[self.pos(x, y)]

    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return

    def show(self):
        for i in range(self.h + 2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i + 1)])

    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return

    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy


def solve():
    n = getN()
    nums = getList()
    sumn = sum(nums)
    ans = 0
    for num in nums:
        ans += (num * (sumn - num)) % MOD
        ans %= MOD
    print(ans // 2)
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in a:s+=i

ans = 0
for i in a:
    ans += (s-i)*i
    ans = ans%(10**9 + 7)

print(int(ans/2))

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
mod=10**9+7
sum_a=sum(A)

ans=0
for i in range(N):
    sum2=sum_a-A[i]
    ans+=sum2*A[i]
    ans%=mod

print(ans//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from fractions import Fraction as frac

MOD = 1e9 + 7

def solve(case_no):
    n = int(input())
    a = list(map(int, input().split()))
    ps = [a[0]]
    for i in range(1, n):
        ps.append(ps[i - 1] + a[i])
    ans = 0
    for i in range(n - 2, -1, -1):
        ans += a[i + 1] * ps[i]
        ans %= MOD
    print(int(ans))

t = 1
# t = int(input())
for i in range(1, t + 1):
    solve(i)

Submission status: Wrong Answer

Solution code:
import math
from fractions import Fraction as frac

MOD = 1e9 + 7

def solve(case_no):
    n = int(input())
    a = list(map(int, input().split()))
    ps = [a[0]]
    for i in range(1, n):
        ps.append(ps[i - 1] + a[i])
    ans = 0
    for i in range(n - 2, -1, -1):
        ans += a[i + 1] * ps[i]
        ans %= MOD
    print(ans)

t = 1
# t = int(input())
for i in range(1, t + 1):
    solve(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
As = list(map(int, input().split()))
MOD = 10**9 + 7
S = sum(As)%MOD
ans = 0
for a in As:
    ans += (a * (S-a))%MOD
    ans %= MOD
print(ans//2)

Submission status: Wrong Answer

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

MOD = 1e9 + 7
res = 0
sum = 0

for n in v:
  res = (res + n * sum) % MOD
  sum = (sum + n) % MOD

print(int(res))

Submission status: Wrong Answer

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

s = sum(a)
s %= 10**9+7
ans = 0
for ai in a:
  ans += ai*s
  ans -= ai**2
  ans %= 10**9+7
print((ans//2)%(10**9+7))

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

total = 0
for a in A:
    total += a
    total %= MOD

ans = 0
for a in A:
    ans += (a * total) % MOD
    ans -= a * a
    ans %= MOD

ans //= 2
ans %= MOD

print (ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

n = int(input())
A = [int(a) for a in input().split()]
s = sum(A)
AA = np.array(A)
ss = sum(AA*AA)
S = -ss
mod = 1000000000+7
for a in A:
    S += s*a
S = S//2
print(S%mod)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    mod =10**9+7

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

    ss =sum(A) %mod
    sm =ss *ss % mod
    for i in A:
        sm -= i*i
        sm %=mod
    sm //= 2
    sm %=mod
    print(sm)






if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def read_ints():
    return map(int, input().split(' '))


input()
a = list(read_ints())
s = sum(a)
ans = 0
mod = int(1e9 + 7)
for i in a:
    ans = (ans + i * (s - i)) % mod
print(ans // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
s = sum(a*a for a in A)
ans = sumA*sumA - s
print(ans//2)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    A = in_nl()

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

    print(ans // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

s = sum(A) % mod
ans = s*s % mod - sum(a*a for a in A)
print(ans // 2 % mod)

Submission status: Wrong Answer

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

import sys
input=sys.stdin.readline

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
ans=0
sums=sum(arr)
for val in arr:
    ans+=(val*sums)%mod
    ans-=(val*val)%mod
print((ans%mod)//2)

Submission status: Wrong Answer

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

res = sum([a[i] ** 2 for i in range(n)])
s = sum(a)
ans = ((s ** 2 % mod) - res) // 2
ans %= mod

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
num = sum(lis)% (10 ** 9 + 7)
ans = 0
for i in range(n):
  ans += lis[i] * (num-lis[i])
  ans %= 10 ** 9 + 7
while ans < 0:
  ans += 10 ** 9 + 7
print(ans//2)

Submission status: Wrong Answer

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

s = sum(a)
ans = 0
for ai in a:
  ans += ai*s
  ans %= 10**9+7
for ai in a:
  ans -= ai**2
  ans %= 10**9+7
print(ans//2)

Submission status: Wrong Answer

Solution code:
LI = lambda: list(map(int, input().split()))

N = int(input())
A = LI()

MOD = 10 ** 9 + 7


def main():
    s = sum(A) % MOD
    ans = s * s % MOD
    for a in A:
        ans = (ans - a ** 2) % MOD
    ans = ans // 2 % MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [i* i for i in a]
print((sum(a)**2 - sum(b))//2)

Submission status: Time Limit Exceeded

Solution code:
def main(N, A):
    ans = 0
    for i in range(N-1):
        ans += A[i]*sum(A[i+1:])
        ans %= 10**9 + 7
        """
        for j in range(i+1, N):
            ans += A[i]*A[j]
            ans = ans % (10**9 + 7)
        """
    return ans

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    ans = main(N, A)
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

all_sum = 0
count = 1

for i in range(n - 1):
  all_sum += a[i] * sum(a[count:len(a)])
  count += 1

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input(""))
val = list(map(int,input().split()))
val_sum = 0
mod = 10**9 + 7

for i in range(num):
    for j in range(i+1,num):
        val_sum = val_sum + val[i]*val[j]
        
print(val_sum%mod)

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]
        ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
for i,ai in enumerate(A):
  total += ai * sum(A[i+1:])
print(total % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sumA = []
for i,ai in enumerate(A):
  sumA.append(sum(A[i+1:]))

for i,ai in enumerate(A):
  total += ai * sumA[i]
print(total % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
for i,ai in enumerate(A):
  for aj in A[i+1:]:
    total += ai * aj
    #A[i] * A[j]
#    print(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()))
assert len(A) == N
total = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    total += A[i] * A[j]
#    print(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()))
assert len(A) == N
total = 0
for i in range(0, N):
  for j in range(i+1, N):
    total += A[i] * A[j]
#    print(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()))
mod = 1000000000 + 7
add = 0
for i in range(N):
    tmp = sum(A[i+1:N])
    add += tmp * A[i]
print(add%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

answer = sum % mod
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = sum([x*y % mod for x in A[0:N-1] for y in A[A.index(x)+1:N]])%mod

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


ans = 0
mod = 7 + 10**9

for i in A:
	i %= mod

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

ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

mod = 7 + 10**9
s = 0

for i in range(N-1): 
	for	j in range(i+1, N):
		t = A[i] * A[j] % mod
		s += t

ans = s % mod
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
ans = 0

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

for cnt_1 in range(N-1):
  for cnt_2 in range(cnt_1+1, N):
      ans = (ans + (A[cnt_1] * A[cnt_2]) % MOD ) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
ans = 0

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

for cnt_1 in range(N-1):
  for cnt_2 in range(cnt_1+1, N):
      ans = (ans + (A[cnt_1] * A[cnt_2])) % MOD

print(ans)

Submission status: Time Limit Exceeded

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

MOD = int(1e9+7)

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy
n=input()
l=list(map(int, input().split()))
res=0
#print(f"le{len(l)}")
l.append(0)
l.reverse()
for i in range(len(l)): 
    #print(l[len(l)-1-i],numpy.cumsum(l)[len(l)-i-2])
    res+=l[len(l)-1-i]*numpy.cumsum(l)[len(l)-i-2]
    #print(f"{res}レス")
print(res%(10**9+7))

Submission status: Time Limit Exceeded

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

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

# answer = s % (10**9+7)
print(s)

Submission status: Time Limit Exceeded

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

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

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

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]

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

Submission status: Time Limit Exceeded

Solution code:
n=input()
l=list(map(int, input().split()))
res=0
#print(f"le{len(l)}")
for i in range(len(l)):
    for j in range(i+1,len(l)):
        res+=l[i]*l[j]
        #print(res)
print(res%(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(N-i-1):
        ANS = ANS + A[i]*A[i+j+1]
print(ANS%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    MOD = 10**9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    
    a_sum = []
    for i in range(n):
        a_sum.append(sum(a[i+1:n]))
    
    for i in range(n-1):
        ans += a[i] * a_sum[i]
        ans %= MOD
    print(ans)
        
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    mod = 10**9 + 7
    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 = (ans + (a[i] * a[j])) % mod
    print(ans)
        
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from itertools import combinations

mod = 10 ** 9 + 7


def main():
    n = int(input())
    ls = list(map(int, input().split()))

    c = combinations(ls, 2)

    ans = 0

    for cc in c:
        ans += cc[0] * cc[1] % mod

    print(ans % mod)


main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from itertools import combinations

mod = 10 ** 9 + 7


def main():
    n = int(input())
    ls = list(map(int, input().split()))

    c = combinations(ls, 2)

    ans = 0

    for cc in c:
        ans += cc[0] * cc[1] % mod

    print(ans % mod)


main()

Submission status: Time Limit Exceeded

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


def solve1(n: int, a: list) -> int:
    mod = 10**9 + 7
    ans = 0
    list_len = len(a)

    for index, val in enumerate(a):
        for i in range(index+1, list_len):
            ans += val * a[i]
            ans %= mod
            #print(val, " * ", a[i], " = ", val*a[i])

    return ans % mod


print(solve1(n, a))

Submission status: Time Limit Exceeded

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

index = 0
product = 0
for i in range(n):
  for j in range(i + 1, n):
    product += arr[j] * arr[i]

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

Submission status: Time Limit Exceeded

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

tot = 0
num2 = [0]*(N-1)

for i in range(len(num)-1):
  num2[i] = sum(num[1+i:]) % (10**9+7)
  
for i in range(len(num)-1):
  num1 = num[i] % (10**9+7)
  
  tot += num1 * num2[i]
  
  if tot >= (10**9+7): tot = tot % (10**9+7)

print(tot)

Submission status: Time Limit Exceeded

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

tot = 0
num2 = [0]*(N-1)


for i in range(len(num)-1):
  num1 = num[i] % (10**9+7)
  num2[i] = sum(num[1+i:]) % (10**9+7)
  
  tot += num1 * num2[i]
  
  if tot >= (10**9+7): tot = tot % (10**9+7)

print(tot)

Submission status: Time Limit Exceeded

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

tot = 0

for i in range(len(num)):
  num2 = sum(num[i+1:])
  #print(num2)  

  tot += (num[i] % (10**9+7)) * (num2 % (10**9+7))
  if tot >= (10**9+7): tot = tot % (10**9+7)

print(tot)

Submission status: Time Limit Exceeded

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

tot=0

for i in range(len(num)):

  tot += (num[i] % (10**9+7) * sum(num[i+1:]) % (10**9+7))
  if tot >= (10**9+7): tot = tot % (10**9+7)

print(tot)

Submission status: Time Limit Exceeded

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

tot=0

for i in range(len(num)):

  tot += (num[i] % (10**9+7) * sum(num[i+1:]) % (10**9+7))
  tot = tot % (10**9+7)

print(tot)

Submission status: Time Limit Exceeded

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

d = 10**9 + 7

ans = 0
for i in range(len(A) - 1):
    ans += A[i] * (sum(A[i+1:]))
print(ans % d)

Submission status: Time Limit Exceeded

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

d = 10**9 + 7

ans = 0
for i in range(len(A) - 1):
    ans += A[i] * (sum(A[i+1:]))
print(ans % d)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

MOD = 10**9 + 7

n = int(input())

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

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys

MOD = 10**9 + 7

n = int(input())

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

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

print(sum % MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
values = input().split(' ')
a = [0] * N

mod = 10 ** 9 + 7
for i in range(N):
    a[i] = int(values[i]) % mod
    
ans = 0
# mod = 10 ** 9 + 7
for i in range(N):
    a[i]
    term = sum(a[i+1:]) % mod
    ans += a[i] * term

ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

sum=0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
values = input().split(' ')
a = [0] * N

for i in range(N):
    a[i] = int(values[i])
    
ans = 0
for i in range(N):
    term = sum(a[i+1:])
    ans += a[i] * term

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
values = input().split(' ')
a = [0] * N

for i in range(N):
    a[i] = int(values[i])
    
ans = 0
for i in range(N):
    for j in range(N):
        if i < j:
            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()))
s = 0
for i in range(1,n):
    for j in range(i):
        pro = a[i] * a[j]
        s = s + pro

mod = s % (10**9 + 7)

print(mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = input().split(" ")

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
a = len(A)
sa = sorted(A)
su = 0
p = 10**9+7
for i in range(a):
        su += sa[i]*(sum(sa[i+1:])%p)%p

print(su%p)