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 sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
import numpy as np
n = int(input())


a = list(map(int, sys.stdin.readline().split()))

mod = 10 ** 9 + 7

sumlist= sum(a)
x = []
for i in range(n):
    x.append(sumlist - a[i])
    sumlist -= a[i]

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

print(ans)

Solution (Python):
import sys
from sys import exit
from math import gcd, factorial, ceil, floor, sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
from heapq import heapify, heappop, heappush
from itertools import permutations, combinations, product, accumulate
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(10**7)

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

N = ii()
A = li()
mod = 10**9+7

ans = 0
m = list(accumulate(A))
for i, x in enumerate(m[:-1]):
    ans += ((A[i]%mod) * ((m[-1] - m[i])%mod))%mod
    ans %= mod
print(ans)

Solution (Python):
import itertools
n=int(input())
a=list(map(int,input().split()))
gou=sum(a)
mod=10**9+7
ans=0

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

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

p = 10 ** 9 + 7

s = sum(A) % p
X = [s]
for i in range(N):
    s = s + p - A[i]
    s %= p
    X.append(s)


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

Solution (Python):
n = int(input())
arr = [int(x) for x in input().split(' ')]

pre = []

for x in arr:
    if len(pre) == 0:
        pre.append(x)
    else:
        pre.append(pre[len(pre)-1] + x)
        
ans = 0
mod=int(1e9+7)
for i in range(n):
    s = (pre[n - 1] - pre[i]) * arr[i]
    ans = ((ans % mod) + s % mod) % mod
    
print(ans)

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

Solution (Python):
import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop

input = sys.stdin.buffer.readline

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As,mod=DIV):
    s = 0
    for a in As:
        s += a
        if mod !=None:
            s = s%mod
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    As = isRaw()
    sumAs = list(cumsum(As,DIV))
    ans = 0
    for aidx in range(len(As)-1):
        ans = (ans+As[aidx]*(sumAs[-1]-sumAs[aidx]))%DIV
    print(ans)

main()

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
mod=10**9+7
def do():
    n=INT()
    A=LIST()
    B=[0]*(n)
    B[0]=sum(A[1:])
    ans=0

    for i in range(1,n):
        B[i]=(B[i-1]-A[i])%mod

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

    print(ans)

    

    
if __name__=='__main__':
    do()

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


P = 10**9 + 7
k = 3
inv_t = [0]+[1]
for i in range(2,k):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

N = int(input())
A = list(map(int, input().split()))
AA = [A[i]**2 % mod for i in range(N)]

ans = 0
b = 0
for i in range(N):
    ans = (ans + A[i]) % mod
    b = (b + AA[i]) % mod
ans = ans % mod
b = b % mod

ans = (ans**2) % mod
ans = (ans - b) % mod

ans = (ans*inv_t[2]) % mod
print(ans)

Solution (Python):
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


acum = [0 for _ in range(N+1)]
acum[0] = sum(A)
for i in range(N):
    acum[i+1] = acum[i] - A[i]

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    inlis = list(map(int, input().split()))

    total = sum(inlis)

    tmp = 0

    for i in range(n):
        total -= inlis[i]
        tmp += inlis[i] * total 
        tmp %= (10**9 + 7)
    
    ans = tmp % (10**9 + 7)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    
    t=1
    for _ in range(t):

        n=int(input())
        arr=inar()
        dp=[0]*n
        for i in range(n-1,-1,-1):
            if i==(n-1):
                dp[i]=arr[i]
                continue
            dp[i]=arr[i]+dp[i+1]
        
        ans=0
        mod=10**9+7
        for i in range(n-1):
            ans+=(arr[i]*dp[i+1])% mod
        print(ans%mod)




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")

if __name__ == "__main__":
    main()

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

Solution (Python):
mod = int(1e9 + 7)

def pw(b, ex):
    if ex == 0: return 1
    if ex == 1: return b
    if ex & 1: return b % mod * pw((b*b) % mod, ex >> 1) % mod
    return pw((b*b) % mod, ex >> 1) % mod

n = int(input())
x = list(map(int,input().split()))
st = 0
en = 0

for i in x:
    st = (st + i) % mod
    en = (en + (i * i) % mod) % mod
    
st *= st
ans = int((st - en + mod) % mod)
ans = int(ans * int(pw(2, mod - 2)) % mod) % mod
print (int(ans))

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

MOD = 1000000007

cum = []

s = 0
for a in A:
    s += a
    cum.append(s)


ans = 0
for i, a in enumerate(A):
    c = a * ((s - cum[i]) % MOD) % MOD
    ans += c % MOD
    ans %= MOD

print(ans)

Solution (Python):
n = int(input())
numbers = list(map(lambda x: int(x), input().split()))

sum_n = sum(numbers)
total_value = 0

for current_num in numbers:
    sum_n -= current_num
    total_value += current_num * sum_n


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

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

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

R=[S-L[0]]
for i in range(1,N):
    R.append(R[-1]-L[i])


mod=10**9+7
ans=0
for i in range(N):
    ans += L[i]*R[i]
    ans%=mod
print(ans)

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

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

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

MOD = 10 ** 9 + 7

sum_A = sum(A)
a_a = [(a * a) for a in A]

ans = ((sum_A ** 2)- sum(a_a)) // 2

print(ans % MOD)

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

proA = map(lambda x: x**2, A)

S = ((sum(A)**2-sum(proA))//2)

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

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():

    N = I()
    A = LI()
    mod = 10 ** 9 + 7
    sum_ = 0
    D = []
    for i in range(N):
        a = A[i]
        sum_ += a
        D.append(a ** 2)
    ans = (sum_ ** 2 - sum(D)) // 2
    print(ans % mod)










if __name__ == "__main__":
    main()

Solution (Python):


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


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


def solve():
    N = read_int()
    A = read_ints()
    S = A[0]
    answer = 0
    modulo = 10**9+7
    for i in range(1, N):
        answer = (answer+A[i]*S)%modulo
        S = (S+A[i])%modulo
    return answer


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

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

mod = 10**9 + 7

ans = sum(A) * sum(A) % mod
ans += mod - (sum([a*a for a in A]) % mod)
ans %= mod
if(ans%2==0):
    ans //= 2
else:
    ans = (ans + mod) // 2
    ans %= mod
print(ans)

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

ans = 0
sum_a = sum(A)
for a in A:
  ans = (ans + (sum_a - a)*a)%mod

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

Solution (Python):
MODULO = 1_000_000_007


def main():
    N = int(input())
    A = [int(_x) for _x in input().split()]
    sums = [0]*N
    for i in reversed(range(N)):
        if (i == N-1):
            sums[i] = A[i]
        else:
            sums[i] = sums[i+1] + A[i]

    result = 0
    for i in range(N):
        if i == N-1:
            break
        result = (result + A[i] * sums[i+1]) % MODULO
    print(result)


main()

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

for p in range(N):
    Asum += A[p]
    A2sum += A[p]**2


print(((Asum**2-A2sum)//2)%(10**9+7))

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
a=sum(l[1:])
m=10**9+7
s=0
for v,u in zip(l[:-1],l[1:]):
    s+=v*a
    a-=u
print(s%m)

Solution (Python):
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = LIST()

acc = [0] * (N+1)
for i in range(N):
    acc[i+1] = (acc[i]+A[i]) % MOD

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

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

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

MOD = 10**9+7

sum_j = 0
for v in a:
    sum_j += v
    sum_j %= MOD

ans = 0
for v in a:
    ans += v * ((sum_j - v) % MOD)
    ans %= MOD


class FLT:
    """
    フェルマーの小定理
    a^(-1) = a^(m-2) mod p
    """
    def __init__(self, mod=10**9+7):
        self.mod = mod

    def rep_sqr(self, base, k):
        ans = 1
        while k > 0:
            if k & 1:
                ans = ans * base % self.mod
            base = base * base % self.mod
            k >>= 1
        return ans

    def inv(self, a):
        """ 逆元を取る """
        return self.rep_sqr(a, self.mod-2)

flt = FLT()

ans = ans * flt.inv(2)
ans %= MOD
print(ans)

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

MOD = pow(10, 9) + 7

two_inv = pow(2, -1, MOD)

sq = []

for x in a:
    sq.append(x ** 2 % MOD)

s = sum(a) % MOD
s_sq = sum(sq) % MOD

print((pow(s, 2, MOD) - s_sq) * two_inv % MOD)

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


mod=pow(10,9)+7

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

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

Solution (Python):

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

S = sum(A) % MOD
T = sum([a*a for a in A]) % MOD

ans = (S*S - T) % MOD
if ans % 2 == 1:
	ans += MOD
print(ans // 2)

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

inv_A=A[::-1]

b = [0]*N
b[0]=inv_A[0]
for i in range(1,N):
    b[i] = (b[i-1]+inv_A[i])%mod
inv_b = b[::-1]

print( sum(A[i]*inv_b[i+1]%mod for i in range(0,N-1))%mod )

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
an=0;md=10**9+7
suf=[0]*n
suf[-1]=l[-1]
for i in range(n-2,-1,-1):
  suf[i]=suf[i+1]+l[i]
for i in range(n-1):
  an=(an+l[i]*suf[i+1])%md
print(an)

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

print(kotae%mod)

Solution (Python):
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

mod=1000000007
n = r()
a = rl()
b = [a[-1]]
for i in range(n-2,-1,-1):
    b.append(b[-1]+a[i])
b = b[::-1]
ans = 0
for i in range(n-1):
    ans= (ans+(a[i]*b[i+1])%mod)%mod
print(ans)

Solution (Python):
import os
import heapq
import sys,threading
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

sys.setrecursionlimit(10 ** 5)
threading.stack_size(2**27)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""


def inpt():
    return [int(k) for k in input().split()]


def main():
    n=int(input())
    ar=inpt()
    sm=0
    ans=0
    md=10**9+7
    for i in range(n-1):
        sm+=ar[i]
        temp=(sm%md * ar[i+1]%md)%md
        ans=(ans+temp)%md
    print(ans)






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")

if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate
n=int(input())
A=[int(i) for i in input().split()]

B=list(accumulate(A))

s = 0 
for i in range(n):
    s += A[i]*(B[-1]-B[i])
    s %= (10**9+7)
print(s)

Solution (Python):
import sys

if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    m = 10 ** 9 + 7
    s = sum(a) % m
    ans = 0
    running = 0
    for i in range(n):
        running += a[i]
        ans += (a[i] * (s - running))
        ans %= m
    ans %= m
    print(ans)
    return



n = RN()
a = RA()
solve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A_sum = sum(A)
MOD = 10**9 + 7
ans = 0
A_cum = 0
for a in A:
    A_cum += a
    ans += a  * (A_sum - A_cum) % MOD
print(ans % MOD)

Solution (Python):
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    A = NLI()
    
    sum_A = sum(A)
    ans = 0
    
    for n in range(N):
        sum_A -= A[n] 
        ans += (A[n] * sum_A)%MOD
        ans = ans % MOD
    print(ans)
        



if __name__ == '__main__':
    main()

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

s = sum(l)%mod
ans = 0

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

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

sum = sum(A)
ans = 0
M = 10**9 + 7

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n=int(input())
L=list(map(int,input().split()))
total = 0
hb = sum(L)
val = 0
for i in range(n-1):
    val +=L[i]
    total += L[i]*(hb-val)
print(total%mod)

Solution (Python):
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import itertools
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=list(map(int,pin().split()))
  mod=10**9+7
  B=list(itertools.accumulate(A))
  ans=0
  for i in range(N-1):
    ans+=A[i]*(B[N-1]-B[i])
  print(ans%mod)
  return 
main()

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

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

print(ans%mod)

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

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

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

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

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

Solution (Python):

import sys

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    from itertools import accumulate
    acc = list(accumulate(reversed(A), lambda a,b: (a+b)%MOD))[::-1]
    ans = 0
    for i in range(N-1):
        ans = (ans + A[i] * acc[i+1] % MOD) % MOD
    return ans



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)]  
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

print(ans)

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

n = iinp()
a = lmiinps()

ans = 0
count = 0

for i in range(n):
    count += (a[i]%(10**9+7))

for i in range(n):
    count -= a[i]
    ans += (a[i]%(10**9+7))*count


ans %= (10**9+7)

print(ans)

Solution (Python):
import sys

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

    sum_A = sum(A)
    cum_A = [sum_A]
    for a in A[:N-1]:
        cum_A.append(cum_A[-1] - a)

    res = 0
    mod = 1000000007
    for i, a in enumerate(cum_A[1:]):
        res += A[i] * a
        res %= mod

    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
def findProductSum(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    return (array_sum_square - 
            individual_square_sum) // 2

n = int(input())
arr = list(map(int,input().split()))
mod = (10**9)+7
print(findProductSum(arr,n)%mod)

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

Asum=[0]
for i in A:
  Asum.append(Asum[-1]+i)

s=sum(A)
ans=0

for i,v in enumerate(A):
  ans+=v*(Asum[-1]-Asum[i+1])
  ans%=10**9+7

print(ans)

Solution (Python):
import sys
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = A[::-1]
    B = list(itertools.accumulate(A))
    MOD = 10**9+7
    ans = 0
    for i in range(N - 2, -1, -1):
        ans = (ans + A[i + 1] * B[i]) % MOD
    print(ans)


if __name__ == '__main__':
    main()

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

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

sums = 0
for a in A:
    sums += a
    sums %= mod

ans = 0

for a in A:
    sums = (sums - a) % mod
    ansi = (sums * a) % mod
    ans += ansi
    ans %= mod

print(ans)

Solution (Python):
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
s = [0] * (n+1)

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


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

print(ans)

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

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

sum_a=sum(a)%MOD
total=0
for i in range(len(a)):
    sum_a=(sum_a-a[i])%MOD
    total = (total+sum_a*a[i])%MOD

print(total%MOD)

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

a=[int(i) for i in input().split()]
mod=10**9+7
goal=0
ans=0
for i in range(n):
    taishou=a.pop()
    if i != 0:
        ans+=taishou*goal
        ans=ans%mod
    goal+=taishou


print(ans)

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

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


N = int(input())
A = LI()
total = sum(A)
ans = 0
mod = pow(10, 9)+7
for i in range(N-1):
    total -= A[i]
    ans = (ans+total*A[i]) % mod
print(ans)

Solution (Python):
from itertools import accumulate

n = int(input())
a = [int(x) for x in input().split()]
p = list(accumulate(a))
m = 10 ** 9 + 7

result = 0
for i, x in enumerate(a):
  result += x * (p[-1] - p[i])
  result %= m

print(result)

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

p = 1000000007
n = int(input())
v = list(map(int, input().split()))

s = sum(v)
ss = 0
for i in range(n):
    ss += (v[i] * v[i])

ans = (s*s - ss) // 2
print(ans % p)

Solution (Python):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
A = rl()

pref = []
s = 0
for a in A:
	s += a
	pref.append(s)
ans = 0
for i in range(N-1):
	ans += pref[i] * A[i+1]
	ans = ans % mod
print(ans)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
rui = [0]*N
rui[0] = a[0]
mod = 10**9+7
for i in range(1,N):
    rui[i] = rui[i-1] + a[i]
ans = 0
for i in range(1,N):
    ans = (ans + a[i] * rui[i-1])%mod
print(ans)

Solution (Python):
import sys,os
import math
from fractions import Fraction 
from collections import defaultdict
from random import randint





def linput():
    return list(minput())

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



n=int(input())
a=linput()

ans,s=0,0
mod=10**9+7
for i in a:
    s=(s+i)%mod
now=0
for i in a:
    now+=i
    cur=(s-now)%mod
    ans=(ans+(i*(cur))%mod)%mod
print(ans)

Solution (Python):
import sys

MOD = 10**9 + 7

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

sumA = 0
for A in As:
    sumA += A
    sumA %= MOD


ans = sumA * sumA % MOD
for A in As:
    ans -= A * A % MOD
    ans %= MOD


inv2 = pow(2, MOD-2, MOD)
ans *= inv2
ans %= MOD

print(ans)

Solution (Python):
from sys import stdin,stdout
from itertools import accumulate
n=int(stdin.readline());M=10**9+7
a=list(map(int,stdin.readline().split()))
ps=list(accumulate(a[::-1]))[::-1]
ans=0
for i in range(n-1):
    ans=(ans+a[i]*(ps[i+1]))%M
print(ans%M)