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:
N = int(input())
A = input().split(' ')
a = 0
sum = 0
for i in range(1, N):
    sum += int(A[i])
for i in range(N):
    a += int(A[i]) *  sum
    if i < N - 1:
        sum -= int(A[i + 1])
    
print(int(a % (10e9 + 7)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)
y=sum(l)
t=(x-y)//2
print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
  print(a[0])
else:
  l=list(map(lambda z:z**2,a))
  x=sum(a)
  y=sum(l)
  t=(x-y)//2
  print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
	print(a[0])
else:
	l1=list(map(lambda z:z**2,a))
	x=sum(a)**2
	y=sum(l1)
	t=(x-y)//2
	print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())

l = 10000000073
a=list(map(int,input().split()))
s = sum(a)
num = 0
for i in range(n):
  s = s- a[i]
  num =num+a[i]*s
else:
  print(num%l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
 
a=list(map(int,input().split()))
s = sum(a)
num = 0
for i in range(n):
  s = s- a[i]
  num =num+a[i]*s
else:
  print(num)

Submission status: Wrong Answer

Solution code:
n=int(input())
 
a=list(map(int,input().split()))
s = sum(a)
num = 0
for i in range(n):
  num = num - a[i]
  num = a[i]*num
else:
  print(num)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0

#累積和、二乗和の両方でまとめて求める
#for x in A:
#  sum += x
#  sum %= (10**9+7)
sum = A.sum() % (10**9+7)

sum2 = 0
#for x in A:
#  sum2 += x*x
#  sum2 %= (10**9+7)
sum2 = (A**2).sum() % (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0

#累積和だけは1項ずつ求めてmodをとる
for x in A:
  sum += x
  sum %= (10**9+7)
#sum = A.sum() % (10**9+7)

sum2 = 0
#for x in A:
#  sum2 += x*x
#  sum2 %= (10**9+7)
sum2 = (A**2).sum() % (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = sum(li)%mod
li2 = [x**2 for x in li]
S2 = sum(li2)%mod

print((S**2-S2)//2%mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)
sum = A.sum() % (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)
sum2 = (A**2).sum() % (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = A.sum()
sum %= (10**9+7)

sum2 = (A**2).sum()
sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
mod = 1e9 + 7
total = 0
for n in numbers:
    total += n
    total %= mod

ans = 0
for n in numbers:
    total -= n
    if total < 0:
        total += mod
    ans += n * total
    ans %= mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)
sum *= sum
sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = sum - sum2 % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= ((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
s = sum(a)
ans = 0
for x in a:
  ans += (s-x) * x
  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)
ans = 0
for x in a:
  ans += (s-x) * x
  ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
mod = 1e9 + 7
numbers_r_cumsum = numbers[N - 1:0:-1].cumsum()[::-1]
each = numbers[:N-1] * numbers_r_cumsum
total = 0
for e in each:
    total += e
    total %= mod
print(int(total))

Submission status: Wrong Answer

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

Sum = sum(A)

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

ans %= 1000000007

print(int(ans/2))

Submission status: Wrong Answer

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

Sum = 0

for i in range(N):
    Sum += int(A[i])

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

ans %= 1000000007

print(int(ans/2))

Submission status: Wrong Answer

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

s = 0
for i in range(n):
  s += a[i]
  #sはaの和

t = 0
for i in range(n):
  t += a[i]**2
  #tはaの2乗和

ans = int(((s**2 - t)/2) % (10**9 + 7))
print(ans)

Submission status: Wrong Answer

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

for i in range(0, n):
  for j in range(1, n):
    if i >= j:
      continue
    else:
      ans = ans + (lis[i]*lis[j]) % mod

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
square = sum(numbers)**2
pow_custom = lambda x: int(pow(x, 2))
numbers_pow = int(sum(map(pow_custom, numbers)))
ans = (square - numbers_pow) / 2
print(int(ans % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
# required function 
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum) / 2
 
print(int(findProductSum(a, n))%(10**9+7))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
# required function 
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum) / 2
 
print(int(findProductSum(a, n))%10**9+7)

Submission status: Wrong Answer

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

# required function 
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum) / 2

print(int(findProductSum(a, n)))

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
square = sum(numbers)**2
numbers_pow = sum(map(pow, numbers, [2]*N))
ans = (square - numbers_pow) / 2
print(int(ans % (1e9 + 7)))

Submission status: Wrong Answer

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

sum = 0

for i in a:
  sum += i

s = sum**2

for i in a:
  s -= i**2

s = s/2
  
print(int(s%(10**9+7)))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
SUM=0
for i in A:
    SUM+=i
SUM=SUM*SUM
ANT=0
for i in A:
    ANT+=i*i

print((SUM-ANT)%(10**9+7)//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = list(map(float, input().split()))
square = sum(numbers)**2
numbers_pow = sum(map(pow, numbers, [2]*N))
ans = (square - numbers_pow) / 2
print(int(ans % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
square = sum(numbers)**2 / 2 % (1e9 + 7)
numbers_pow = sum(map(pow, numbers, [2]*N)) / 2 % (1e9 + 7)
ans = square - numbers_pow
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = list(map(int, input().split()))
square = sum(numbers)**2
numbers_pow = sum(map(pow, numbers, [2]*N))
ans = (square - numbers_pow) / 2
print(int(ans % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
import numpy as np
from decimal import Decimal
N = int(input())
numbers = np.array(list(map(int, input().split())), dtype=Decimal)
square = numbers.sum()**2
numbers_pow = numbers**2
times_sum = (square - numbers_pow.sum()) / 2
print(int(times_sum % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
numbers = np.array(list(map(int, input().split())))
tri = numbers.sum()**2
numbers_pow = numbers**2
times_sum = (tri - numbers_pow.sum()) / 2
print(int(times_sum % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    _ = int(input())
    nums = tuple(map(int, input().split()))
    mod = 10 ** 9 + 7

    num_sum = 0
    part_sum = 0
    for n in nums:
        num_sum += n
        part_sum += n * n
    zentai = num_sum * num_sum
    print(int(((zentai - part_sum) / 2) % mod))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
S2 = sum(map(lambda x:x**2,A))
 
print(int((S**2-S2)/2%(pow(10,9)+7)))

Submission status: Wrong Answer

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

total_A = 0
for i in range(N):
    total_A = total_A + A[i]

total = total_A * total_A

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

divide = total - total_sq
if divide < 0:
    divide += m

print(int(divide / 2) % m)

Submission status: Wrong Answer

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

total_A = 0
for i in range(N):
    total_A = (total_A + A[i]) % m

total = (total_A * total_A) % m

total_sq = 0
for i in range(N):
    total_sq = (total_sq + A[i] * A[i]) % m

divide = (total - total_sq) % m
if divide < 0:
    divide += m

print(int(divide / 2))

Submission status: Wrong Answer

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

total_A = 0
for i in range(N):
    total_A = (total_A + A[i]) % m

total = (total_A * total_A) % m

total_sq = 0
for i in range(N):
    total_sq = (total_sq + A[i] * A[i]) % m

divide = total - total_sq
if divide < 0:
    divide += m

print(int(divide / 2))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
total = sum(A)
ans = 0
for a in A:
    ans += (total-a)*a
    ans = ans % mod

ans = (ans//2) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
total = sum(A)
ans = 0
for a in A:
    ans += (total-a)*a
    ans = ans % mod

ans = ans // 2
print(ans)

Submission status: Wrong Answer

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

sum = 0
for i in range(n):
  sum += intlist[i]
  sum %= mod

ans = sum*sum%mod

for i in range(n):
  ans -= intlist[i]*intlist[i]%mod
  if ans < 0:
    ans += mod

ans *= (mod+1)/2
ans %= mod
print(int(ans))

Submission status: Wrong Answer

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

sum = 0
for i in range(n):
  sum += intlist[i]
  sum %= mod

ans = sum*sum%mod

for i in range(n):
  ans -= intlist[i]*intlist[i]%mod
  if ans < 0:
    ans += mod

ans *= (mod+1)/2
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())), dtype=np.int64)
mod = 10**9 + 7

sq_sum = (A*A).sum()
sum_sq = A.sum() * A.sum()
answer = (sum_sq - sq_sum) / 2

print(int(answer % mod))

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    mod = 10**9 + 7

    sq_sum = (A*A).sum()
    sum_sq = A.sum() * A.sum()
    answer = (sum_sq - sq_sum) // 2

    print(answer % mod)

main()

Submission status: Wrong Answer

Solution code:
out = 0

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

for i in range(N - 1):
  for j in range(1, N - i):
    out += As[i] * As[i + j]
    
print(int(out % (1E9 + 7)))

Submission status: Wrong Answer

Solution code:
a=s=0
for x in[*open(0)][1].split():x=int(x);a+=s*x;s+=x
print(a%(1e9+7))

Submission status: Wrong Answer

Solution code:

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    ans = 0
    MOD = 10**9 + 7
    s = sum(arr) % MOD

    for num in arr:
        ans = (ans + (s-num)*num) % MOD

    return (ans % MOD) // 2


N = readInt()
arr = readList()

print(solve(N, arr))

Submission status: Wrong Answer

Solution code:

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    s = sum(arr)
    ans = 0
    MOD = 10**9 + 7

    for num in arr:
        ans = (ans + (s-num)*num) % MOD

    return (ans % MOD) // 2


N = readInt()
arr = readList()

print(solve(N, arr))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

mod = 1000000007
s = 0
sq = 0

for i in range(n):
    s += A[i]
    s %= mod
    sq += ((A[i] * A[i]) + mod) % mod

# print(sq)
# print(s)
print(int((((((s * s) + mod) % mod) - sq + mod) % mod)/ 2))

Submission status: Wrong Answer

Solution code:

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    s = sum(arr)
    ans = 0
    MOD = 10**9 + 7

    for num in arr:
        ans = (ans + (s-num)*num) % MOD

    return (ans) % MOD // 2


N = readInt()
arr = readList()

print(solve(N, arr))

Submission status: Wrong Answer

Solution code:

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    s = sum(arr)
    ans = 0
    MOD = 10**9 + 7

    for num in arr:
        ans = (ans + (s-num)*num) % MOD

    return ans // 2


N = readInt()
arr = readList()

print(solve(N, arr))

Submission status: Wrong Answer

Solution code:

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    s = sum(arr)
    ans = 0
    MOD = 10**9 + 7

    for num in arr:
        ans = (ans + ((s-num)*num) % MOD) % MOD

    return ans // 2


N = readInt()
arr = readList()

print(solve(N, arr))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    x = sum(A)

    ans = 0

    for i in range(N):
        x -= A[i]
        y = x%MOD
        z = (y*A[i])%MOD

        ans +=z

    return print(ans)


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

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    all_sum = sum(A) ** 2
    st = 0
    for i in range(N):
        st += A[i] ** 2
    print(int((all_sum - st)/2 % 1000000007))
main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
n = int(sys.stdin.buffer.readline())
a = np.fromstring(sys.stdin.buffer.readline(), dtype=np.int64, sep=' ')
MOD = 10**9+7
ans = 0
for i in range(n-1):
    s = int((a[i+1:]*a[i]).sum())
    ans += s % MOD
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())	
s=0	
su=0	
t=0
k=0
a=list(map(int,input().split()))
if n==1:
	print(a[0])
else:
	for i in range(n):
		s+=a[i]
		k=math.pow(s,2)
		su+=math.pow(a[i],2)
		t=(k-su)//2
	print(round(t))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
y=sum(a[i]**2 for i in range(n))
z=(x*x-y)/2

print(int(z)%1000000007)

Submission status: Wrong Answer

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


def findProductSum(A,n):
    M = 1000000007

    array_sum = 0
    for i in range(len(A)):
        array_sum = (A[i]+array_sum)%M

    array_sum_square = ((array_sum%M) * (array_sum%M))%M
    # print (array_sum_square)

    individual_square_sum = 0
    for i in range(len(A)):
        individual_square_sum = (individual_square_sum + ((A[i]%M) * (A[i])%M)%M)%M

    # print(individual_square_sum)
    if array_sum_square>=individual_square_sum:
        return (array_sum_square - individual_square_sum) / 2
    else:
        ((array_sum_square-individual_square_sum)+M)/2

print(findProductSum(arr, n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = sum(A)
S2 = sum(map(lambda x: x*x,A))

print((S*S - S2) / 2 % 1000000007)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int (input())
a= list(map(int,input().split()))
s2=int(sum(a)*sum(a))
a2=[int(i*i) for i in a]
ans1=int((s2-sum(a2))/2)

print(int(ans1%((10**9)+7)))

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = input().split()

for i in range(N):
   lst[i] = int(lst[i])

sum = 0

for i in range(N - 1):
   for j in range(i + 1, N):
      print(lst[i], lst[j])
      sum += lst[i] * lst[j]

s = 10**9 + 7

if sum < s:
   print(sum)
else:
   print(sum % s)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
su = sum(arr)
c = 0
for item in arr:
  c+= item*item
print((su**2 - c)%(10**9 + 7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int (input())
a= list(map(int,input().split()))
s2=int(sum(a)*sum(a))
a2=[int(i*i) for i in a]
ans1=int((s2-sum(a2))/2)

print(int(ans1%(10**9+7)))

Submission status: Wrong Answer

Solution code:
num = int(input())

line = input()
arr = [int(x) for x in line.split(" ")]

post = [0 for x in range(num)]
post[num - 1] = arr[num - 1]

for i in range(2, num + 1):
  post[num - i] = post[num-i+1] + arr[num - i]
  
sum = 0

for i in range(num-1):
  sum += arr[i] * post[i+1]
  #sum %= 1e9 + 7

sum %= 1e9 + 7
print(int(sum))

Submission status: Wrong Answer

Solution code:
num = int(input())

line = input()
arr = [int(x) for x in line.split(" ")]

post = [0 for x in range(num)]
post[num - 1] = arr[num - 1]
for i in range(2, num + 1):
  post[num - i] = post[num-i+1] + arr[num - i]
  
sum = 0

for i in range(num-1):
  sum += arr[i] * post[i+1]
  sum %= 1e9 + 7
  
print(int(sum))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)
c = 0
for a in A:
  c += a**2
print((sumA**2 - c)/2 % (10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split(" ")))
s = 0
for i in range(0,N):
  s += a[i]

s = s*s

for i in range(0,N):
  s -= a[i]*a[i]

while s >= 2*(10**9 +7):
  s = s % 2*(10**9 +7)
s = s/2
 
print(int(s))

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
a_list=list(map(int,input().split()))
sum=0
ps=np.cumsum(a_list)
for i in range(n-1):
  sum+=a_list[i]*(ps[n-1]-ps[i])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
mod=10**9+7
S=sum(a)%mod
T=sum([i*i for i in a])%mod
print((S*S-T)%mod)

Submission status: Wrong Answer

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

MOD = 1000000007
ans = 0
powsum = 0
sumpow = 0
for i in range(N):
    powsum += A[i] 
    sumpow += (A[i]*A[i])

powsum = (powsum*powsum)
ans = (powsum-sumpow)/2.0
print(int(ans)%MOD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input()) 
A = list(map(int,input().strip().split()))[:n] 
# def findProductSum(A,n): 
  
#     product = 0
#     for i in range (n): 
#         for j in range ( i+1,n): 
#             product = product + A[i]*A[j] 
#     return product 
# print(findProductSum(A,n))
def findSumofProduct(A, n): 
    sum = [None for _ in range(n)] 
    sum[n-1] = A[n - 1] 
  
    # finding suffix sum  
    for i in range(n - 2, -1, -1): 
        sum[i] = sum[i + 1] + A[i] 
  
    # finding the sum of product of  
    # each element with suffix sum.  
    res = 0
    for i in range(n - 1): 
        res += sum[i + 1] * A[i] 
    return res 
  
# Driver Code 
# A = [9, 3, 4, 2] 
# n = len(A) 
print(findSumofProduct(A, n)) 
  
# This code is contributed 
# by SamyuktaSHegde

Submission status: Wrong Answer

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

for i in range(n):
	total += l[i]
	b += l[i] **2
a = int((total**2 - b) / 2 % 1000000007)
print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
  m=1000000007
  n=int(input())
  a=np.array(list(map(int,input().split())))
  b=np.flipud((np.cumsum(np.flipud(a)))[:-1])
  a=a[:-1]
  c=a*b
  d=np.sum(c)
  e=d%m
  print(e)
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
wa = 0
a = 0
for l in range(N-1):
    a += A[N-l-1]
    wa += a * A[N-l-2]
print(wa)

Submission status: Wrong Answer

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

for i in range(n):
	total += l[i]
	b += l[i] **2
a = int((total**2 - b) / 2 % (10 **9 + 7))
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
liste = list(map(int, input().split()))
liste.sort()
summ = 0
for i in range(0, len(liste)):
    for j in liste[i+1:n]:
        if liste[i] >= 1 and j <= n%(10**9)+7 and liste[i] < j:
            summ += liste[i] * j
print(summ)

Submission status: Wrong Answer

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

for i in range(n):
	total += l[i]
	b += l[i] **2
a = (total**2 - b) / 2 % (10 **9 + 7)
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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


mod = 10**9+7
s = sum(A)

ans = 0

for i in range(n):
    s -= A[i]
    ans += (A[i] * s) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
  m=1000000007
  n=int(input())
  a=np.array(list(map(int,input().split())))
  b=np.cumsum(a[:-1])
  a=a[1:]
  c=a*b
  d=np.sum(c)
  e=d%m
  print(e)
main()

Submission status: Wrong Answer

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