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
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    R = list(accumulate(A))
    res = 0
    for i in range(n):
        res += (A[i] * (R[-1] - R[i])) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7

    n=I()
    lis=LI()
    S=0
    sm1=0
    for i in range(n):
        S=(S+lis[i])%mod
    S=((S%mod)**2)%mod
    for i in range(n):
        sm1=sm1+((lis[i]%mod)**2)%mod
    ans=(((S-sm1)%mod)*pow(2,mod-2,mod))%mod
    
    
    print(ans)
            
        
if __name__=="__main__":
    main()

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()

    sum_A = 0
    sum_pow2 = 0
    for a in A:
        sum_A += a
        sum_A %= P
        sum_pow2 += a**2
        sum_pow2 %= P
    
    print((sum_A**2 % P - sum_pow2)%P*pow(2,P-2,P)%P)


    
main()

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
MOD = 1000000007
class ModInt(int):
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other)

    def __sub__(self, other):
        return ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other)

    def __mul__(self, other):
        return ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other)

    def __floordiv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, MOD - 2, MOD))
        else:
            if other == 0:
                raise ZeroDivisionError
            else:
                return ModInt(self.x * pow(other, MOD - 2, MOD))

    def __pow__(self, other):
        return ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD))

    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x)

    __rmul__ = __mul__

    def __rfloordiv__(self, other):
        return ModInt(other.x * pow(self.x, MOD - 2, MOD)) if isinstance(other, ModInt) else ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, MOD))

def main():
    n = int(input())
    A = list(map(lambda x: ModInt(int(x)), input().split()))
    print((sum(A) ** 2 - sum(a ** 2 for a in A)) // 2)



if __name__ == '__main__':
    main()

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

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

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

acc = [As[0]]
for i in range(1, N):
    tmp = acc[-1] + As[i]
    acc.append(tmp % MOD)

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

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

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

if __name__ == '__main__':
    main()

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

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

p=10**9+7

sumA=sum(A)

A2=0
for i in range(n):
  A2+=A[i]*A[i]

print(((sumA*sumA-A2)//2)%p)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cumA = [0]
for i in range(N):
  cumA.append(cumA[-1] + A[i])

ans = 0
M = 10**9 + 7
for i in range(N-1):
  ans += (A[i]*(cumA[N]-cumA[i+1]))
  ans %= M
print(ans)

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

mx = 10**9 + 7

su = sum(A)
ans = 0

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

print(ans % mx)

Solution (Python):
N = int(input())
P = 10 ** 9 + 7
X = 0
Y = 0
for a in map(int, input().split()):
  X += a ** 2
  Y += a
  X %= P
  Y %= P
print(((Y ** 2 % P - X) * pow(2, P - 2, P)) % P)

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

mod = int(1e+9 + 7)

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

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
m=10**9+7
x=sum(S)%m
r=0
m=10**9+7
def div(a,b):
    return (a*pow(b,m-2,m))%m
for s in S:
    r=(r+s*(x-s))%m
print(div(r,2))

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


if __name__ == '__main__':
    resolve()

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

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

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

print(ans)

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
Mod=10**9+7
sa=sum(A)
sb=0
ans =0
for a in A:
  sb += a
  ans += (sa - sb)%Mod * a
  ans%=Mod

print(ans)

Solution (Python):
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

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

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()



N = In.int()
A = In.ints()
MOD = 10**9+7

presum = [A[0]]

for i in range(1, len(A)):
    presum.append(presum[-1]+A[i])

ans = 0

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

Out.int(ans)



if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

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

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

print(ans)

Solution (Python):
n = int(input())
aa = tuple(map(int, input().split()))

MOD = 10 ** 9 + 7

ans = 0
x = sum(aa)
for i in range(n):
    x -= aa[i]
    ans += aa[i] * x
    ans %= MOD
print(ans)

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

Solution (Python):
from itertools import accumulate

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

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

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

M = (10**9)+7
n = int(input())
As = map(int, input().split(" "))

cumsum = []
cur = 0
out = 0
for i in range(n-1):
    cur += As[i]
    out += cur*As[i+1] 
    out = out % M
print(out)

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

sumL = []
totalSum = sum(listA)
for a in listA:
    totalSum-=a
    sumL.append(totalSum)

ans = 0
for i in range(len(listA)):
    ans += listA[i]*sumL[i]%(10**9 + 7)
    ans %= (10**9 + 7)
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")

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 Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

from math import gcd

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n = int(ri())
a = Ri()

pre = [0]*n
for i in range(n-1,-1,-1):
    if i == n-1:
        pre[i] = a[i]
    else:
        pre[i] = pre[i+1]+a[i]

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

Solution (Python):
import itertools as it

MOD = 10**9 + 7
N = int(input())
a = list(map(int, input().split()))
s = list(it.accumulate(a))
ans = 0
for i in range(N - 1):
    ans += s[i] * a[i + 1]
    ans %= MOD
print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")



def main():
    N = int(input())
    A = list(map(int, input().split()))
    s = sum(A)**2
    t = 0
    for a in A:
        t += a**2
    
    ans = (s - t) // 2
    print(ans % 1000000007)


if __name__ == '__main__':
    main()

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

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

ans = ((sum(A)*sum(A) - tmp)//2)%(10**9+7)
print(ans)

Solution (Python):


import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = map(int,read().split())

MOD = 10**9+7
i2 = (MOD+1)//2


r = sum(a)
r *= r
r -= sum(i*i for i in a)

r *= i2
print(r%MOD)

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

MOD = 10 ** 9 + 7

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

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

print (ans)

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

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

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")


MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
s = 0
for i in range(N):
    a = A[i]
    s += a
    s %= MOD
t = s*s
for i in range(N):
    a = A[i]
    t -= a*a
    t %= MOD
t %= MOD
if t % 2 == 0:
    print(t // 2)
else:
    print((t+MOD)//2)

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

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  A=LI()

  l=[0]
  for x in A:
    l.append(l[-1]+x)

  

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

  return ans


print(main())

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
sm = sum(a) % mod
ans = 0
beki = 0

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

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)









INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    N, *A = map(int, read().split())
    SUM = sum(A)
    ans = 0
    for a in A:
        ans += ((SUM - a) * a)%mod
        ans %= mod
        SUM -= a
    print(ans)


if __name__ == "__main__":
    run()

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

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

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

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

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

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

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

Solution (Python):
MOD = 10**9 + 7
N = input()
A = [int(hoge) for hoge in input().split()]
S = 0
Scube = 0
for a in A:
    S += a
    Scube += a**2
    S %= MOD
    Scube %= MOD
Double = S**2 - Scube
Double %= MOD
if Double%2:
    Double += MOD
    Double //= 2
else:
    Double //= 2
print(Double)

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))



def main():
	n=II()
	A=LI()

	m=10**9+7

	S=sum(A)
	S%=m
	ans=0


	for i in A:
		S-=i
		S%=m
		ans+=i*S
		ans%=m
	print(ans)









if __name__ == "__main__":
	main()

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

n = INT()
a = LIST()
b = 0

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

print(ans)

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

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

print(ans%mod)

Solution (Python):
MOD=10**9+7
N=int(input())
ls=[int(s)%MOD for s in input().split()]
s=0
d=0
for x in ls:
  s=(s+x)%MOD
  d=(d+x*x)%MOD

ans=((s*s-d)*500000004)%MOD
print(ans)

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(z%1000000007)

Solution (Python):


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

mod = pow(10,9)+7

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

total = 0
for i in range(1,N+1):
    bubun_sum = (ruiseki[-1]-ruiseki[i])%mod
    bubun_total = (A[i-1]*bubun_sum)%mod
    total = (total+bubun_total)%mod

print(total)

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

for i in range(n-1):
	answer = (answer+a[i]*b[i+1])%MOD
print(answer)

Solution (Python):
MOD = 1000000007
n, *a = map(int, open(0).read().split())
wa = a + [0]
for i in range(n-1, 0, -1):
    wa[i-1] += wa[i]

ans = 0
for i in range(n):
    ans += a[i] * wa[i+1]
    ans %= MOD
print(ans)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
n = ni()
A = lma()
mod=10**9+7
tot = 0
for a in A:
    tot = (tot+a)%mod
ans = 0
for a in A:
    tot =(tot-a)%mod
    ans+=(tot*a)%mod
print(ans%mod)

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

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

dig = 0
for i in range(N):
  dig += (A[i] ** 2 % MOD)
  
ans = (ans**2 - dig) % 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()))
asum = []
tmp = sum(a)
for i in a:
    tmp -= i
    asum.append(tmp)

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

Solution (Python):
import sys


def _i(): return int(sys.stdin.readline().strip())


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


MOD = 10**9 + 7


def main():
    n = _i()
    a = list(_ia())
    s = [0] * n
    for i in range(n-2, -1, -1):
        s[i] = s[i+1] + a[i+1]

    ans = 0
    for ai, si in zip(a, s):
        ans = (ans + (ai * si)) % MOD
    return ans


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

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

NUM = 1000000007
inv2 = 500000004
assert (inv2 * 2) % NUM == 1

As2 = 0
A2s = 0

for a in A:
    As2 += a
    As2 %= NUM
    
    A2s += a ** 2
    A2s %= NUM

As2 = (As2 ** 2) % NUM

ans = (As2 + NUM - A2s) % NUM
ans *= inv2
ans %= NUM

print(ans)

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

a = sum(A)
a *= a

for i in range(N):
  a -= A[i]*A[i]
  
print(a//2%(10**9+7))

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
MOD = int(1e9+7)
k = (MOD + 1) // 2

ans = sum(a)**2 % MOD
for ai in a:
    ans -= ai**2
    ans %= MOD
ans *= k
ans %= MOD
print(ans)

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

mod = 10**9 + 7

s = sum(A)
ans = 0
for i, a in enumerate(A):
    s -= a
    ans = (ans + s * a) % mod

print(ans)

Solution (Python):
n, *a = map(int, open(0).read().split())
mod = 10 ** 9 + 7

s = [0] * n

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

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

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

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

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

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

Solution (Python):
MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]


S = [sum(A) % MOD]
for i in range(N):
    S.append(S[-1]-A[i])

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

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

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

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

mod = 10 ** 9 + 7

s = sum(A)

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

print(ans)

Solution (Python):



mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))
s = 0
ss = 0
for ai in a:
    s += ai
    ss += ai*ai
    s %=mod
    ss %=mod

x = pow(2,mod-2,mod)
ret = (s*s-ss)%mod
ret = ret*x
ret %=mod

print(ret)

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

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = list(accumulate(A))
MOD = 10**9 + 7
res = 0
for i in reversed(range(1,N)):
    res += S[i-1]*A[i]
    res %= MOD
print(res)

Solution (Python):
from itertools import accumulate

m = 1000000007

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

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

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

mod = 10**9 + 7

S = 0
T = 0

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

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

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

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

print(ans)

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

mod = 10**9+7

su = sum(A)

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

print((ans * 500000004)%mod)

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

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

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

print(ans)

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

Solution (Python):

P = 1000000007
n = int(input())
a = [int(i) for i in input().split()]
pref = [0]*n
pref[n-1] = a[n-1]
for i in range(n-2,-1,-1):
	pref[i] = pref[i+1]+a[i]

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

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

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

res = 0
M = 10 ** 9 + 7
for i, a in enumerate(A[:-1], start=1):
    res += a * (prefix[N] - prefix[i])
    res %= M
print(res)

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

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A_sum = sum(A)
A2 = sum([i*i for i in A])
print(((A_sum * A_sum - A2)//2) % (10**9+7))

Solution (Python):
def mod(num):
    return num % (10 ** 9 + 7)


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

Asum = sum(A)

ans = 0

for i, a in enumerate(A):
    Asum -= a
    ans = mod(ans + Asum * a)

print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    cumsum = [0]
    for i in range(N):
        cumsum.append(cumsum[i] + A[i])
    ans = 0
    for i in range(N):
        ans += (A[i] * ((cumsum[N] - cumsum[i+1]) % mod)) % mod
        ans %= mod
    print(ans)

main()

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

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
A.reverse()
sumA=[0,]+list(accumulate(A))
mod=10**9+7
ans=0
for a, s in zip(A, sumA):
    ans+=((a%mod)*(s%mod))%mod
    ans%=mod
print(ans)

Solution (Python):
n = int(input())
a_ls = list(map(int, input().split()))
csum = [0] * n
now = 0
for i in range(n):
    now += a_ls[i]
    csum[i] = now

mod = 10**9+7
ans = 0
for i in range(n):
    add = a_ls[i] * ((csum[-1] - csum[i])%mod)
    add %= mod
    ans += add
    ans %= mod
print(ans%mod)

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

ans = 0

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

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

for i in range(len(a)):
  am-=a[i]
  sm=(sm+a[i]*am)%(10**9+7)
print(sm)

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))
from itertools import accumulate
AA = [0] + list(accumulate(A))
mod = 10**9+7

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