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):
N = int(input())
As = list(map(int, input().split()))
S = 0
T = 0
for i in range(N):
  S += As[i]
  T += (As[i] * As[i]) % 1000000007


A = S*S % 1000000007
B = T % 1000000007
X = (A - B) % 1000000007

print((X * int((1000000007 + 1)/2)) % 1000000007)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
S = sum(a)
S2 = sum(map(lambda x:x*x, a))
print((S*S-S2)//2%mod)

Solution (Python):
n = int(input())
alist=list(map(int,input().split()))

mod = (10**9 + 7)
ans = 0

import numpy
alistsum = numpy.cumsum(alist)
asum = sum(alist)

for i in range(n-1):
    ans += alist[i]*(asum - alist[i])
    asum -= alist[i]
    ans = ans%mod
print(ans)

Solution (Python):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = [int(x) for x in input().split()]
s = sum(seq[1:])
ans = 0
m = 10**9 + 7
for i in xrange(n-1):
    ans = (ans + (seq[i] * s)) % m
    s -= seq[i+1]
print(ans)

Solution (Python):
N=int(input())
A = [int(x) for x in input().split()]
s=sum(A)
x=0
for i in range(N):
    s=s-A[i]
    x+=s*A[i]    
print(x%(10**9+7))

Solution (Python):
from itertools import accumulate
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
Ac = list(accumulate(A))

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

Solution (Python):

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

mod = 10 ** 9 + 7

s = sum(A)** 2

a = 0
for i in A:
    a += (i ** 2)

ans = (s - a) // 2
ans = ans % mod

print(ans)

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

Solution (Python):
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)

Solution (Python):
MOD=10**9+7

N=int(input())
A=list(map(int,input().split()))
S=sum(A)**2%MOD
for i in range(N):
    S=(S-A[i]**2+MOD)%MOD
print(S*pow(2,MOD-2,MOD)%MOD)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
k = 0
num = sum(a)
import math

for i in range(n):
    reje = num - a[i]
    k += reje * a[i]

x = k//2
t = 10 ** 9 + 7
ans = x % t
print(ans)

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

sum = 0
for i in a:
    sum += i

sum = sum * sum

for j in a:
    sum = sum - j*j

sum = (sum // 2) % 1000000007 
print(sum)

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

sm = sum(A)

ans = 0
for s in range(len(A)-1):
    
    sm -= A[s]
    ans += A[s]*sm

print(ans%mod)

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    
    N = int(input())
    A = list(map(int, input().split()))

    return N, A


def main(N: int, A: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 整数(2 <= N <= 2 * 10**5)
        A (list): 整数(0 <= A_i <= 10**9)
    """
    
    mod = 10**9 + 7
    ans = 0
    sum_A_j = sum(A)
    for i in range(N):
        A_i = A[i]
        sum_A_j -= A_i
        ans += A_i * sum_A_j
        ans %= mod

    
    print(ans)


if __name__ == "__main__":
    
    N, A = get_input()

    
    main(N, A)

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

MOD = 1000000007

a = 0
b = 0
for i in range(N):
    a += A[i] % MOD
    b += (A[i] ** 2) % MOD
a = a ** 2
ans = (a - b) * pow(2, MOD - 2, MOD) % MOD
print(ans)

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

Solution (Python):
from sys import stdin
import numpy as np
input = stdin.readline
n = input().rstrip()
n = int(n)
a = list(map(int, input().split()))
a = np.array(a)
suma = np.cumsum(np.array(a))

ans = 0
for i in range(n-1):
    x = suma[n-1] - suma[i]
    x %= 1000000007
    ans += a[i] * x
    ans %= 1000000007

print(ans)

Solution (Python):
import sys

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

n = ri()
a = rl()
s = sum(a)
ans = 0
for i in a:
    s -= i
    ans = (ans + s*i)%mod
print(ans)

Solution (Python):
import itertools as itr

a = int(input())
p = list(map(int,input().split()))
mod = 10**9 + 7
ans =0
sum_list = list(itr.accumulate(p))
for i in range(len(p)-1):
    o = p[i+1]
    w =sum_list[i]
    ans = (ans+o*w%mod)%mod
print(ans)

Solution (Python):

import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 

from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

N = int(input())
A = list(map(int, input().split()))
MOD = int(1e9) + 7

ans = 0
acc = 0
for i in A:
    ans += i * acc
    acc += i
    ans %= MOD
    acc %= MOD

print(ans)

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

k = 1000000007

sm = sum(A)

ans = 0
for s in range(len(A)-1):
    
    sm -= A[s]
    ans += A[s]*sm

if ans>1000000007:
    print(ans%k)
else:
    print(ans)

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

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

Solution (Python):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    mod = (10 ** 9) + 7
    csum = sum(a)

    for i in range(n):
        csum -= a[i]
        ans += a[i] * csum

    ans = int(ans % mod)
    print(ans)
 
resolve()

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

Solution (Python):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=sum(A)**2
ans-=sum(map(lambda x: x**2, A))
ans//=2
print(ans%MOD)

Solution (Python):
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
mod = 10**9+7
mod_sum = 0
a_sum = sum(a)
for i in range(n-1):
    a_sum -= a[i]
    mod_sum += (a[i] % mod) * (a_sum % mod) % mod

print(mod_sum%mod)

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

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

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

Solution (Python):
n = int(input())
mod = int(1e9+7)
ans, t = 0, 0
for a in list(map(int, input().split())):
    ans = (ans+a*t) % mod
    t += a

print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
 
partial_sum = A.copy()
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%(10**9+7))
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%(10**9+7)) %(10**9+7)
print(int(res))

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

mod = 10**9 + 7

S = [0]
for i in range(n):
  S.append(A[i] + S[i])

ans = 0

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))

MOD = 1000000007

def mod(n):         
  return n % MOD

def multiply(a, b): 
  return mod(mod(a)*mod(b))

ans = sum(lst)**2

for i in range(n):
  ans -= lst[i]**2
  
ans = ans//2
print(mod(ans))

Solution (Python):
n = int(input())
mod = int(1e9+7)
ans, t = 0, 0
for a in list(map(int, input().split())):
    ans = (ans+a*t) % mod
    t = (t + a) % mod

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = [0]
ans = 0
MOD = 1000000007
for i in range(0, n, 1):
    s.append((s[i] + a[i]) % MOD)

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

print(ans % MOD)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
S = 0
ans = 0
for k in range(N):
  S = S + A[k]

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9+7

partial_sum = A.copy()
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))

Solution (Python):
N = int(input())

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

partial_sum = A.copy()
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))

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

tmp=0
T=0
for i in range(N-1):
  T=T+A[i]
  
  
  tmp=(A[i]*(S-T)+tmp)
tmp=tmp%(10**9+7)
print(tmp)

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

Solution (Python):
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    mod = 10**9+7
    a_sum = sum(A)
    a_cum = [0] * (n+1)
    for i in range(n):
        a_cum[i + 1] = a_cum[i] + A[i]
    ans = 0
    for i in range(len(A)-1):
        ans += A[i] * (a_sum - a_cum[i+1]) % mod
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    sum_a = sum(a_list)
    ans = 0

    for i in range(n - 1):
        sum_a -= a_list[i]
        ans += (a_list[i] * sum_a) % mod

    print(ans % mod)


if __name__ == "__main__":
    main()

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

a2=[a[n-1]]
for i in range(n-1,0,-1):
    a2.append(a2[-1]+a[i-1])
ans=0
for i in range(n-1):
    ans = ( ans + (a[i]*a2[-i-2]) )%(10**9+7)
print(ans)

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

Solution (Python):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    mod = 10 ** 9 + 7
    s = 0
    sq = 0
    for i in range(n):
        s += a[i]
        sq += (a[i]) ** 2
        s %= mod
        sq %= mod
    s2 = (s ** 2) % mod

    ans = s2 - sq
    if ans < 0:
        ans += mod

    divs = pow(2, mod-2, mod)

    print((ans*divs)%mod)

resolve()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = sum(A)
new_A = A.reverse()
n = 0
for i in range(N-1):
    n += A[i]*(B-A[i])
    B = B-A[i]

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

Solution (Python):
from itertools import accumulate

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

mod = 10 ** 9 + 7

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

print(ans)

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


ans = 0
B = [0] * (N + 1)

for i in range(N-1, -1, -1):
    B[i] = (B[i+1] + A[i]) % D

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

print(int(ans % D))

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

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

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

print(Asum)

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

mod = 10**9+7

cs = [0]
for a in A:
    cs.append(cs[-1]+a)
cs = cs[1:]

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

Solution (Python):
import copy

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

partial_sum = copy.deepcopy(A)
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))

Solution (Python):


def main(N, A_list):
    total_list = []
    total = 0
    for i in range(len(A_list)):
        total += A_list[i]
        total_list.append(total)

    num = 0
    for i in range(len(A_list)-1):
        num += A_list[i] * (total_list[len(A_list)-1]-total_list[i])

    val = num % ((10 ** 9) + 7)
    print(val)


N = int(input())
A_list = list(map(int, input().split()))
main(N, A_list)

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))
ans = 0
mod = 10**9 +7
accum = list(accumulate(A))

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

Solution (Python):













from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
import time



MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): 
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): 
    return reduce(math.gcd, numbers)

def combination(m,n): 
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): 
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    now = sum(A)
    ans = 0
    for i in range(N-1):
        now -= A[i]
        ans += ((A[i]%MOD) * (now%MOD)) % MOD
    print(ans%MOD)
main()

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
import numpy as np





sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    cumsum = [A[0]]
    for n in range(1, N):
        cumsum.append(cumsum[n - 1] + A[n])

    ret = 0
    for n in range(N):
        ret += A[n] * (cumsum[-1] - cumsum[n])
        ret %= MOD
    print(ret)


if __name__ == '__main__':
    main()

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

my_sum = [0]


tmp = 0
c = 0
for i in a:
    my_sum.append(my_sum[c]+i)
    c += 1



my_sum2 = 0
length = len(my_sum)

c = 0
for i in a:
    my_sum2 += i * (my_sum[length-1] - my_sum[c+1])
    c += 1

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

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]









n = I()
a = LI()
cnt = 0
s = 0
s = sum(a)
for k in a:
    cnt += k**2
ans = (s**2-cnt)//2
print(ans%mod)

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

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

Solution (Python):
from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) 

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

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

mod=10**9+7
total = sum(a)
cum=[]

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

print(ans%mod)

Solution (Python):
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

    ans *= pow(2, mod - 2, mod)
    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

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

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

print(ans % mod)

Solution (Python):
mod = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]
S = sum(A) % mod

ans = 0
for i in range(N):
    S -= A[i]
    if S < 0: S += mod

    ans += S * A[i]
    ans %= mod
print(ans)

Solution (Python):
from itertools import accumulate

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

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

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

for i in range(n):
    k = k + (a[i] * num) - (a[i] ** 2)

x = k // 2
t = 10 ** 9 + 7
ans = x % t
print(ans)

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    ans = 0

    B = [sum(A[1:])]
    for i, a in enumerate(A[1:-1]):
        B.append(B[i] - a)

    for i, ai in enumerate(A[:-1]):
        ans += (ai * B[i])
    
    print(ans % MOD)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

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

Solution (Python):




n = int(input())

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

MOD = 10 ** 9 + 7

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



ans = 0
j = 1
for i in range(n - 1):
    ttl = a[i] * wa
    ans += ttl

    wa -= a[j]
    j += 1

    

print(ans % MOD)

Solution (Python):
from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

k = 0
s = [0] * n
for i in range(n-1, 0, -1):
    k += a[i] % MOD
    s[i] = k

for i in range(n-1):
    ans += a[i] * s[i+1]

ans = ans % MOD

print(ans)

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

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

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

print(ans)

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

a.sort()

temp = sum(a)
ans = 0

for i in a:
    temp -= i
    ans += i * temp
    ans = ans % 1000000007

print(ans)

Solution (Python):
M = 10**9+7

def factorial(n):
    f = 1
    for i in range(1,n+1):
        f = f*i%M
    return f

def comb(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    return perm(n,k)*inverse(factorial(k))%M

def mcomb(n,k):
    return comb(n+k-1,k)

def perm(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    p = 1
    for i in range(n-k+1,n+1):
        p = p*i%M

    return p

def inverse(a):
    return pow(a,M-2,M)

def main():
    n = int(input())
    a = tuple([int(t)for t in input().split()])

    s = sum(a)

    ans = 0

    for a_i in a:
        ans += s*a_i
        ans -= a_i**2

        ans %= M

    ans *= inverse(2)

    ans %= M

    print(ans)
    
    
if __name__ == "__main__":
    main()

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

for i in range(N):
    hoge = hoge - A[i]
    if hoge < 0:
        hoge = hoge + mod
    ans = ans + A[i] * hoge
    ans = ans % mod

print(ans%mod)

Solution (Python):
from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

k = 0
s = [0] * n
for i in range(n-1, 0, -1):
    k += a[i] % MOD
    s[i] = k

for i in range(n-1):
    ans += a[i] * s[i+1]

ans = ans % MOD

print(ans)

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

Solution (Python):
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))

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

total = 0
sums = []
tmp = 0

for i in range(1, N):
    tmp += nums[N-i]
    sums.append(tmp)

for i in range(N-1):
    a = nums[i]
    b = sums[N-(i+2)]
    total += a*sums[N-(i+2)]

print(total % (1000000000+7))

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

print(ans)

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

MOD = 10**9 + 7

ans = 0
t = 0
for i in range(N-1):
  t += A[-1-i]
  ans += A[-2-i] * t % 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):
n = int(input())
A = [*map(int, input().split())]
S = [0] * (n+1)
for i in range(n): S[i+1] = S[i] + A[i]
MOD = (10**9)+7
ans = 0
for i in range(n): ans = (ans + A[i] * (S[-1] - S[i+1])) % MOD
print((ans + MOD) % MOD)

Solution (Python):
n = int(input())
a_int = list(map(int, input().split()))

squ = 0
num = 10 ** 9 + 7

a_sum = 0
for i_sum in range(1, n):
    a_sum += a_int[i_sum]

for i in range(0, n-1):
    squ += a_int[i] * a_sum
    a_sum -= a_int[i+1]

ans = squ % num
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
a = [num % MOD if num >= MOD else num for num in a]

sum_list = [0]
for i in range(n):
	sum_list.append((a[i] + sum_list[i]) % MOD)


ans = 0
for i in range(len(a)):
	ans += a[i] * (sum_list[-1] - sum_list[i + 1])
	ans %= MOD

print(ans)

Solution (Python):
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a





def exEuclid(a, b):
    if (b==0):
        return (a, 1, 0)
    else:
        (dd, xx, yy) = exEuclid(b, a % b)
        return (dd, yy, xx - (a//b)*yy)

def main(n,a):
    MOD=10**9+7
    sum1=0
    sum2=0
    for i in range(n):
        sum1=(sum1+a[i])%MOD
        sum2=(sum2+(a[i]*a[i]))%MOD

    aa=(sum1*sum1-sum2+MOD)%MOD

    d,x,y=exEuclid(2,MOD)
    if x<0:
        x+=MOD
    

    return (aa*x)%MOD

def main2(n,a):
    MOD=10**9+7
    ruiseki=[0]*n
    ruiseki[0]=a[0]
    for i in range(1,n):
        ruiseki[i]=(ruiseki[i-1]+a[i])%MOD
    sum=0
    for i in range(n-1):
        sum=(sum+(a[i]*(ruiseki[n-1]-ruiseki[i]))%MOD)%MOD
    return sum

if __name__=='__main__':
    n,a=readinput()
    ans=main2(n,a)
    print(ans)

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

Solution (Python):

def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

    sum_A = sum(A) % mod
    ans = 0
    for a in A:
        sum_A += mod - a if sum_A < a else -a
        ans += a * sum_A
        ans %= mod
    print(ans % mod)


if __name__ == '__main__':
    main()

Solution (Python):
import base64
import subprocess


exe_bin = "e??420s

exe_bin = base64.b85decode(exe_bin)

with open("./kyomu", 'wb') as f:
    f.write(exe_bin)

subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)

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

mod=10**9+7
total = sum(a)
cum=[]

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

print(ans%mod)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
ans = 0
res = [A[0]]
for i in range(N-1):
    res.append(res[i]+A[i+1])
for i in range(1,N):
    ans = ans + (A[i]*res[i-1])%mod
ans = ans%mod
print(ans)

Solution (Python):
n,*l=map(int,open(0).read().split())

print(int((sum(l)**2 - sum([a**2 for a in l])) // 2) % (10**9 + 7))

Solution (Python):
MODINT = 1000000007
n = int(input())
A = list(map(int,input().split()))
prodsum = [0]*n
prodsum[0] = A[0]
for i in range(1,n):
    prodsum[i] = prodsum[i-1]+A[i]

ans = 0
for i in range(n-1):
    ans += A[i]*(prodsum[-1]-prodsum[i])
print(ans%MODINT)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
M = 10**9 + 7
s = 0

sm = sum(A)

for i in range(N):
    sm -= A[i]
    s += sm * A[i]
    s = s % M

print (s)

Solution (Python):



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

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

ans = sum(a) * sum(a)
print(((ans - res)//2) % (10 ** 9 + 7))

Solution (Python):
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    sm = sum(A) % (10**9 + 7)

    ans = 0
    for a in A:
        sm -= a
        ans += sm * a
        ans %= (10**9 + 7)
    print(ans)

resolve()

Solution (Python):
m = 1000000007

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

result = 0
a = 0
for i in range(1, N + 1):
    result += a * A[N - i]
    a += A[N - i]
    result %= m
print(result)

Solution (Python):
nn = int(input())
aa = list(map(int, input().split()))
bb = [0]*(nn-1)
mysum = 0
for i in range(nn):
    mysum += (aa[i] % (10**9 + 7))
mydiff = 0

for i in range(1,nn):
    mydiff += aa[i - 1]
    tete = mysum - mydiff
    if tete >= 0:
        bb[i-1] = tete
    else:
        bb[i-1] = tete + 10**9+7

finalsum = 0
for i in range(nn-1):
        finalsum += aa[i]*bb[i]
        finalsum = finalsum % (10**9 + 7)

print(finalsum)