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):
def examA():
    D,T,S = LI()
    if (D-1)//S<T:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    S = SI()
    T = SI()
    s = len(S)
    t = len(T)
    ans = t
    for i in range(s-t+1):
        cnt = 0
        for j in range(t):
            if S[i+j]!=T[j]:
                cnt += 1
        ans = min(ans,cnt)

    print(ans)
    return

def examC():
    N = I()
    A = LI()
    S = sum(A)
    cnt = 0
    for a in A:
        cnt += (S-a)*a
        cnt %= mod
    ans = cnt * pow(2,mod-2,mod) % mod
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    la = rli()
    su = sum(la)
    ans = 0
    mod = 10**9+7
    for a in la:
        su -= a
        ans += su*a
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

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

    sa=sum(A)%mod
    sa2=0
    for a in A:
        sa2+=a**2
        sa2%=mod
    i2=pow(2,mod-2,mod)
    print((sa**2-sa2)%mod*i2%mod)


if __name__ == "__main__":
    main()

Solution (Python):
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

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

yes = "Yes"
no = "No"


def main():
    n = ii()
    a = li()
    s = sum(a)
    ss = 0
    for i in a:
        ss += i**2
    print(((s**2 - ss) // 2) % 1000000007)


main()

Solution (Python):


'''
Author: andyli
Time: 2020-08-29 19:58:34
'''

import os
from io import BytesIO, IOBase
import sys

MOD =  10**9+7

def inv(x): return pow(x,MOD-2,MOD)
def main():
    n = int(input())
    a = list(map(int,input().split()))
    S = [1]
    for i in range(1,n):
        S.append(S[i-1]+a[i])
    ans=0
    for i in range(n):
        ans += a[i]*(S[n-1]-S[i])%MOD
        ans %= MOD
    print(ans)
    return



BUFSIZE = 1048576


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)
def input(): return sys.stdin.readline().rstrip('\r\n')




if __name__ == '__main__':
    main()

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

s=sum(a)

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

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

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

print(ans)

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

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

Solution (Python):
n = int(input())
a= list(map(int, input().split()))
s=sum(a)
INF=1000000007
ans=0

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    s = sum(A) % MOD
    ans = 0

    for x in A:
        s = s - x
        s %= MOD
        ans += s * x
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]

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

ans = 0

for i in range(n):
    total -= a[i]
    ans += a[i] * total
    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 = 0
s2 = 0
for a in A:
    s2 = (s2 + a*a) % mod
    s = (s + a) % mod

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mod =10**9+7
sd=0
sdd = 0
for i in a:
    sd+=i**2
    sdd +=i
    sd %= mod
    sdd %=mod
print((sdd**2-sd)*(5*10**8+4)%mod)

Solution (Python):
import numpy as np

n = int(input())

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

s = [0]

for i in a:
  s.append(s[-1]+i)

ans = 0
for i in range(len(a)):
  ans += a[i]*s[i]

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

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

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

Solution (Python):


import os,sys
from io import BytesIO, IOBase

def main():
    mod = 10**9+7
    n = int(input())
    arr = list(map(int,input().split()))
    lst = [arr[-1]]
    for i in range(n-2,-1,-1):
        lst.append(lst[-1]+arr[i])
    ans = 0
    for i in range(n-1):
        ans += (arr[i]*lst[-i-2])%mod
        ans %= mod
    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):
N = int(input())
A = list(map(int,input().split()))
X = sum(A)
out = 0
p = 10**9+7
for i in range(N-1):
    X = X-A[i]
    out =  (out+A[i]*X)%p
print(out)

Solution (Python):
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A = list(mi())

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

    print(((t*t-s)//2)%MOD)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(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-1):
    ans += A[i] * (s[-1] - s[i+1])
    ans %= mod

print(ans)

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

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

Solution (Python):


import sys
input=sys.stdin.readline

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
s1 = 0
s2 = 0
M = 10**9+7
for item in a:
    s1 += item
    s2 += item**2
    s1 %= M
    s2 %= M
ans = (s1**2 - s2)*pow(2, M-2, M)
print(ans%M)

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

po = sum(a) % mod

ans = 0

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

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

ans %= mod

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

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod=10**9+7
n=int(input())
a=lmp()
s=sum(a)%mod
ans=0
for i in range(n):
    s-=a[i]
    s%=mod
    ans+=a[i]*s
    ans%=mod
print(ans)

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

kMod = (10**9) + 7

ans = 0
s = 0

for a in A:
    ans += s * a
    s += a
    s %= kMod
    ans %= kMod
print(ans)

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

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

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

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

sum_a = [0]
for v in a:
    sum_a.append(sum_a[-1] + v)

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

print(res)

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

sm = 0
ans = 0
for e in a:
    ans += e * sm
    ans %= mod
    sm += e
    sm %= mod

print(ans)

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

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

S = 0
T = 0

for i in range(N):
    S += A[i] **2
    T += A[i]
    S %= MOD
    T %= MOD

print((T**2 - S) * pow(2, MOD - 2, MOD) % MOD)

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

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

print(ans)

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


main()

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

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

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

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

N = cin()[0]
A = cin()
S = sum(A)
INF = 10 ** 9 + 7
ans = 0
for i in range(N):
    S -= A[i]
    ans += A[i] * S
    ans %= INF
print(ans)

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7
n=I()
A=LI()
ret=sum(A)
r=0
for i in range(n):
    r+=(ret-A[i])*A[i]
    r%=mod

print(r*pow(2,mod-2,mod)%mod)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
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 LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N = I()
A = LI()
mod = 10**9+7

ans = sum(A)**2
ans %= mod
a = sum(A[i]**2 for i in range(N))
a %= mod
ans -= a
ans *= pow(2,mod-2,mod)
ans %= mod
print(ans)

Solution (Python):
N = int(input())
A = map(int, input().split())
s = 0
ss = 0
MOD = 10 ** 9 + 7
for v in A:
    s += v
    ss += v * v
    s %= MOD
    ss %= MOD

out = s * s - ss
out %= MOD
if out % 2 == 1:
    out += MOD
out //= 2
print(out)

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

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

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

Solution (Python):
'''
自宅用PCでの解答
'''
import math

import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    sm = sum(a)%mod
    ans = (sm**2)%mod
    for i in a:
        ans -= i**2
        ans %= mod

    print((ans*500000004)%mod)

    return None

if __name__ == '__main__':
    main()

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

def twosekisum(A):
    return (sum(A)**2-sum([i**2 for i in A]))//2
print(twosekisum(A)%(10**9+7))

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

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

ans = 0
for i,a in enumerate(A):
    ans += a*(cums[-1] - cums[i+1])
    ans %= MOD
print(ans)

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

L = [0] * N
L[0] = A[0]
for i in range(1, N):
  L[i] = L[i - 1] + A[i]

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

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

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

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

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

An = [int(i) for i in input().split()]
S = sum(An)
Sn = S**2
Sn2 = 0
for a in An:
    Sn2 += a**2

ans = ((Sn - Sn2)//2)%(10**9+7)
print(ans)

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

MOD = 10**9+7

t = sum(A)**2
d = sum(a*a for a in A)
print(((t-d)//2)%MOD)

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

print(ans)

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

MOD = 10**9+7

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

res = 0
res2 = 0
for a in A:
    res = (res + a)%MOD
    res2 = (res2 + a*a)%MOD


print(pow(2, MOD-2, MOD)*(res**2 - res2)%MOD)

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

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = sum(A)
    mod = 10**9 + 7
    r = 0
    for a in A:
        S -= a
        r = (r + S * a) % mod
    return r

print(main())

Solution (Python):


from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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


def main():
	N = int(input())
	A = getlist()
	S = sum(A)
	S %= con
	ans = 0
	for i in range(N):
		ans += A[i] * (S - A[i])
		ans %= con

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

if __name__ == '__main__':
	main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]



def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = IL()
S = sum(A)

SS = sum(a*a for a in A)

print(((S*S-SS)//2)%MOD)

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

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

MOD = 10 ** 9 + 7


def modinv(x):
    return pow(x, MOD - 2, MOD)


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


if __name__ == "__main__":
    main()

Solution (Python):
n=input()
a=[int(i) for i in raw_input().split()]
s=0
for i in a:
    s+=i
c=0
for i in a:
    c+=i*s-i*i
print (c/2)%(10**9+7)

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, -1, mod)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = [0] * (n+1)
    for i in range(n):
        c[i+1] = c[i] + a[i]

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

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

ans = 0
s = sum(a)
for i in range(n):
    ans += (s-a[i]) * a[i]
print((ans//2)%1000000007)

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

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
Asum = list(accumulate(A))
X = Asum[-1]

ans = 0
for i, a in enumerate(A[:-1]):
    ans += a * (X - Asum[i])
    ans %= mod

print(ans)

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

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

Solution (Python):
import sys

n, *aaa = map(int, sys.stdin.buffer.read().split())
ans = sum(aaa) ** 2
ans -= sum(a ** 2 for a in aaa)
ans //= 2
print(ans % (10 ** 9 + 7))

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

ssum = sum(a)

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

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

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

Solution (Python):
def solve():
    n = int(input())
    arr = list(map(int, input().split()))
    arr_sum = sum(arr)
    arr_sum_sqr = arr_sum**2
    res = sum(i**2 for i in arr)
    res = (arr_sum_sqr - res) // 2
    print(res % (10**9+7))


def main():
    t = 1
    while t > 0:
        solve()
        t -= 1


main()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
sm = sum(a)
res = 0
div = pow(2, mod - 2, mod)
for x in a:
  res += x * (sm - x)
  res %= mod
print(res * div % mod)

Solution (Python):
from itertools import accumulate

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

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

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

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

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

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

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