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

Solution (Python):

"""

import numpy as np
i4 = np.int32
i8 = np.int64
MOD = 1000000007


def mod_inv(mod, a):

    old_s, s = 1, 0
    old_t, t = 0, 1
    old_r, r = mod, a

    while r != 0:
        quotient = old_r // r

        old_r, r = r, old_r - quotient * r
        old_s, s = s, old_s - quotient * s
        old_t, t = t, old_t - quotient * t

    return old_t % mod


def main(in_file):
    stdin = open(in_file)
    stdin.readline()
    A = np.array([int(x) for x in stdin.readline().split()])
    s1 = (np.sum(A) % MOD) ** 2 % MOD
    s2 = sum(A ** 2 % MOD) % MOD
    ans = (s1 - s2) % MOD * mod_inv(MOD, 2) % MOD
    print(ans)


def main2():
    main('/dev/stdin')
"""
import os, sys
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
if len(sys.argv) == 1:
    import subprocess
    if p == "":
        pymain = "./" + pymain
    subprocess.call(pymain)
else:
    import gzip, base64, stat
    gz = b'H4sIAMuAUF8C/+19C3hTVbbwSZ/h1QRELO8AEVqQklAebUFJaQMnkkKH8nJGPIQ0pbnmUZMTHo6jYFvHGKtcHR1nfu9c5qXO3Lkz3Hk4jHcuFBGKqFiRN44i8kgJCIrycITctfbeJznnNIHC+D/u/xGlO2udvddee6211177kbMfsdpnZGg0nPTJ4O7iEDINtBDYwvD65xJZAFfCdYO/Q7khXA7AWbJ8Fs6iSC8y0lKqZfkyWbmSDAqXZ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N9jW4JP+ZKdr/IJNphuq84NneyvOCavlJ7W9i5aerzh8e7qM8r5jNyqjLP8VkkqM6r/nKbcpzjen0H1aVl845tbKClkzVuWBV+gNV+cR5KHaUZ/iE1OUT+3aq8tL+qXGO8pxlOv7XqfqftG9tmpPcV5Z/1Pp7RVVeOhewlm3Y/eIa9b+q7v/svFbJPWx/KvPq9beqykvnmaKs4y3RXL1+vGY1T3bOVDqPUOBJLW+tKv0Q/ulk5aVzDiWe1Pyqy59k/EvlpXMJFlb+FRX/an92Qda35OdTo15lR81R1auXOQR5/dL5tKi/a+3PVpVPnNtoYPrTXL18nqq8tH+7/oGr15/Yn9NQnFRe2odtZeXzryG//qx+k9quWPnqLpwLT/V7bn2A9a88LnEObU4K/9NNLjv5vizb8Cu75er+u3ea8iefZf5Dc/Xy/w3NHn+E0JwAAA=='
    bin = gzip.decompress(base64.b64decode(gz))
    with open(pymain, "wb") as f:
        f.write(bin)
    os.chmod(pymain, 0o775)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
mod = 1000000007
for i in range(n):
    sum+=a[i]
for i in range(n):
    sum-=a[i]
    ans+=(a[i]*(sum%mod))
    ans%=mod
print(int(ans))

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

ans = 0
S = sum(lst)

for i in range(n-1):
    S = S - lst[i]
    tmp = lst[i] * S
    ans = (ans + tmp) % mod

print(ans)

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

Solution (Python):
MOD = 1000000007

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

answer = 0
s = sum(A)

for a in A:
    s -=a
    answer += (a * s)
print(answer%MOD)

Solution (Python):



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

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

    return ans


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

    ans = solve(N, A)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N,*A = map(int,open(0).read().split())

S_all = sum(A)**2
diag = sum([a**2 for a in A])

S = S_all-diag
S %= 1000000007
S = (S*pow(2,-1,1000000007))%1000000007

print(S)

Solution (Python):
N,*A = map(int,open(0).read().split())

s = sum(A)
CS = [0 for i in range(N+1)]
CS[0] = s
for i in range(len(A)):
  CS[i+1] = CS[i] - A[i]
CS.pop(0)

S = 0
for i,a in enumerate(A):
  S+=CS[i]*a
  S = (S%1000000007)
print(S)

Solution (Python):
from sys import stdin
inp = lambda : stdin.readline().strip()

n = int(inp())
mod = 10**9 + 7
a =[int(x) for x in inp().split()]
s = [a[0]]
for i in range(1,n):
    s.append(s[i-1]+a[i])
ans = 0
for i in range(n):
    ans +=  ((a[i]%mod) * (s[-1] - s[i])%mod)%mod
    ans %= mod
print(ans)

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

Solution (Python):
def main():
    mod = 10**9+7
    
    n = int(input())
    a = [int(x) for x in input().split()]
    aa = [x**2 % mod for x in a]
    ans = 0
    asum = sum(a) 
    p = asum ** 2 % mod
    q = sum(aa) % mod
    ans = (p - q) % mod
    if ans < 0:
      ans += mod
    if ans % 2 == 1:
      ans += mod
    ans = ans // 2
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    mod = 10**9+7
    
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = 0
    asum = sum(a) 
    for i in range(n):
        asum = asum - a[i]
        ans = ( ans + ((a[i] * asum) % mod)) % mod
    
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
arr = list(map(int, input().strip().split(" ")))

mod = int(1e9)+7
ans = [0]*n
sm = arr[-1]
for i in range(n-2,-1,-1):
    ans[i] = sm
    sm += arr[i]
    sm = sm%mod

fa = 0
for i in range(n):
    fa += ans[i]*arr[i]
    fa = fa%mod
    
print(fa)

Solution (Python):
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=(ans+a[i]*s%mod)%mod
print(ans)

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

mod = 10**9 + 7

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
sup = 10**9 + 7 
sumA = 0
total = 0

for i in range(0,N-1):
    sumA += A[i]
    if sumA > sup:
        sumA %= sup
    total += sumA*A[i+1]
    if total > sup:
        total %= sup

print(total)

Solution (Python):
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
    ans %= mod
print(ans)

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

Solution (Python):


class main:
  def function(n, a):
    mod = 10 **9 +7
    S = [0] * (n + 1)
    for i in range(n):
      S[i + 1] = S[i] + a[i]
    SN = S[-1]
    ans = 0
    for i in range(n - 1):
      cnt = a[i] * (SN - S[i + 1])
      ans += cnt
    print(ans % mod)



if __name__ == "__main__":
  n = int(input())
  a = list(map(int, input().split()))
  main.function(n,a)

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
SUM = 0
jsum= 0
MOD = 1000000007
for j in range(N):
    jsum = (jsum + A[j]) % MOD

for i in range(N-1):
    jsum = (jsum - A[i]) % MOD
    SUM = ( SUM + (jsum * A[i] % MOD ) ) % MOD


print(SUM)

Solution (Python):


n=int(input())

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

mod = 10 ** 9 + 7

sum = 0
for i in range(n):
    sum += a[i]

s = 0
for i in range(n-1):
    sum -= a[i]
    s = (s + a[i] * sum) % mod
print(s)

Solution (Python):
import itertools
N = int(input())
a = list(map(int,input().split()))
a2 = itertools.accumulate(a)
b = [0]
b += list(a2)
s = 0
for i in range(N):
    s += (a[i] * (b[-1] - b[i+1]))
print(s % (10**9+7))

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

sum_A = 0
S = []

for i in range(1,N):
    sum_A += A[-1*i]
    S.append(sum_A)

ans = 0

for i in range(N-1):
    tmp = A[N-2-i] * S[i]
    ans += tmp

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

Solution (Python):
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    N = i_input()
    A = i_list()

    cumulative_sum = list(accumulate(map(lambda x:x%MOD,A)))

    sum = 0

    for i in range(1,N):
        sum = (sum + A[i-1] * (cumulative_sum[N-1]-cumulative_sum[i-1]))%MOD

    print(sum)
    return

if __name__ == '__main__':
    main()

Solution (Python):

md=10**9+7
t=1


for some_num in range(0,t):
    n=int(input())
    vals=[int(i) for i in input().split(" ")]

    s=0
    for i in range(0,n):
        s=(s+vals[i])%md

    csum=0

    for i in range(0,n-1):
        s-=vals[i]

        csum= (csum+vals[i]*s)%md

    print(csum)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

mod=10**9+7

total=sum(a)

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

print(ans)

Solution (Python):


n=int(input())  
a=list(map(int,input().split()))  
mod=int(1e9+7)


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

Solution (Python):
import numpy as np


def main():
    n = int(input())
    As = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    As_sum = sum(As)
    ans = 0

    for i in range(n):
        As_sum -= As[i]
        ans += As_sum * As[i]
        ans %= mod
    ans %= mod
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
x = [sum(a)]
for i in a:
    x.append((x[-1]-i)%mod)
r = 0
for i in range(len(a)-1):
    r = (r+a[i]*x[i+1])%mod
print(r)

Solution (Python):
import numpy as np


def main():
    n = int(input())
    As = list(map(int, input().split()))
    mod = 10**9 + 7

    As_sum = np.sum(As) % mod
    ans = 0
    for i in range(n):
        As_sum -= As[i]
        As_sum %= mod
        ans += As_sum * As[i]
        ans %= mod
    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split())) 
 
goukei = 0

sumA = sum(A)
for i in range(N):
    a = A[i]
    sumA = sumA - a
    goukei = goukei + sumA*a

k = 10**9 + 7
print(goukei%k)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
sum_a = 0
sum = 0

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

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

print(ans)

Solution (Python):
import sys; input = sys.stdin.readline
mod = int(1e9)+7
n = int(input())
lis = list(map(int, input().split()))
pre = [0]*n
pre[0] = lis[0]
for i in range(1, n): pre[i] = pre[i-1] + lis[i]
ans = 0
for i in range(1, n): ans = (ans + (lis[i-1]*(pre[n-1] - pre[i-1]))%mod)%mod
print(ans)

Solution (Python):
n = int(input())
arr = [int(x) for x in input().split()]
arr.insert(0,0)
prefix = [0 for x in range(n+1)]
for i in range(1,n+1):
    prefix[i] = prefix[i-1]+arr[i];

ans = 0
mod = int(1e9+7)
for i in range(1,n):
    ans += arr[i]*(prefix[n]-prefix[i])
print(ans%mod)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
a=sum(A)
a=a**2
b=0

for j in range(n):
  b+=A[j]**2
if a-b<0:
  c=a-b
  while c<=0:
    c+=mod
  
  ans=c//2
  ans=ans%(10**9+7)
 
else:
  ans=(a-b)//2
  ans=ans%(10**9+7)
 
print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    M = 10**9 + 7

    sa = [0] + list(accumulate(A))
    ans = 0
    for i, a in enumerate(A[:-1]):
        ans += a * (sa[-1] - sa[i+1])
        ans %= M

    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
b[-1]= a[-1]
total = 0
mod = 10**9 + 7
cumsum = sum(a)
for i in range(n-1):
    cumsum -= a[i]
    total = (total + (a[i] * cumsum) % mod) % mod
print(total)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))

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