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 re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy

import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class Point():
    def __init__(self,y,x):
        self.x=x
        self.y=y
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    from queue import PriorityQueue
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

def to10(A):
    ret=0
    for a in range(len(A)-1,-1,-1):
        ret+=X[a]*2**(N-1-a)
    return ret

N=int(input())
A=inputintlist()
S=sum(A)
S%=mod
ans=0
for i in range(N):
    s=(S-A[i]+mod)%mod
    ans+=s*A[i]
    ans%=mod
ans=ans*pow(2,mod-2,mod)%mod
print(ans)

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

mod=(10**9)+7

goukei=0
S=[]
tmp=0
for i in range(N):
    tmp+=T[i]
    S.append(tmp)

for i in range(N-1):
    
    
    goukei+=(T[i]*(S[N-1]-S[i]))
goukei=goukei%mod
print(goukei)

Solution (Python):
mod = 1000000007

N = int(input())

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

S = [0]*N

for i in range(N):
    j = N-1 - i

    if i == 0:
        S[j] = 0
    else:
        S[j] = S[j+1] + A[j+1]

ans = 0

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

print(ans)

Solution (Python):
from itertools import accumulate

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

acum = list(accumulate(A))

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

Solution (Python):
import copy
n = int(input())
a = list(map(int,input().split()))
a_2 = copy.copy(a)
a_2.reverse()
sinu = [0] * n
t = 0
for i in range(n):
    t += a_2[i]
    sinu[i] += t
sinu.reverse()

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

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

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

ans = 0

sum_j = [0] * n
sum_tmp = 0

for i in reversed(range(n)):
    sum_tmp += a[i]
    sum_j[i] = sum_tmp

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

print(ans % mod)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
m = 10**9+7
s = sum(A)
cnt = 0

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

print(cnt)

Solution (Python):
(n,),a = [list(map(int, s.split())) for s in open(0)]
s2 = 0
mod = int(1e9+7)
inv_2 = pow(2, mod-2, mod)
for x in a:
    s2 += pow(x, 2, mod)
    s2 %= mod
a2 = pow(sum(a), 2, mod)
ans = ((a2 - s2) * inv_2) % mod
print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
MOD = 10**9 + 7
sum_ai = a[0]
ans = 0
for ai in a[1:]:
    ans += ai * sum_ai
    ans %= MOD
    sum_ai += ai
print(ans)

Solution (Python):

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

    lst = [sum(A)]
    for j in A:
        lst.append(lst[-1] - j)
    ans = 0
    for index, i in enumerate(A):
        ans += i * lst[index + 1] % mod
    print(ans % mod)


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

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

    sumA=sum(A)

    rsumA=A[0]

    res=0
    mod=pow(10,9)+7

    for i in range(len(A)-1):
        res+=A[i]*(sumA-rsumA)
        res=res%mod
        rsumA+=A[i+1]

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

Solution (Python):
from sys import stdin, stdout
def gmi(): return map(int, stdin.readline().strip().split())
def gms(): return map(str, stdin.readline().strip().split())
def gari(): return list(map(int, stdin.readline().strip().split()))
def gars(): return list(map(int, stdin.readline().strip().split()))
def gs(): return stdin.readline().strip()
def gls(): return list(stdin.readline())
def gi(): return int(stdin.readline())

n = gi()
ar = gari()
c = 0
ans = 0
s = sum(ar)
sub = 0
for i in ar[:-1]:
    sub +=  ar[c]
    ans += i*(s-sub)
    c += 1
print(ans%1000000007)

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

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

total = 0
before = 0
for i in range(len(As) - 1):
    if i == 0:
        total = total + As[i] * sum(As[i+1:])
        before = sum(As[i+1:])
    else:
        total = total + ((before - As[i]) * As[i])
        before = before - As[i]

total = total % (10**9 + 7)

print(int(total))

Solution (Python):
N = int(input())
Alist = list(map(int,input().split()))
M = 10**9+7
Asum = sum(Alist)
Answer = 0
for i in range(len(Alist)):
    Asum -= Alist[i]
    Answer += (Alist[i]%M)*(Asum%M)
    Answer = Answer%M
print(Answer)

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

m=sum(i)

ans=0
for k in range(n):
    ans+=(i[k]*(m-i[k]))
ans=ans//2
ans=ans%(10**9+7)
print(ans)

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

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

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

print(ans%MOD)

Solution (Python):
n=int(input())
a=list(map(int,input().strip().split()))[:n]
s=0;
b=[]
b.append(a[0])
for i in range(1,n):
  b.append(a[i]+b[i-1])
for i in range(0,n):
    s=s+a[i]*(b[n-1]-b[i])
    s=s%1000000007
print(s)

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
val=sum(lst)
prev=0
ans=0
for i in lst:
  prev+=i
  ans+=i*(val-prev)
print(ans%1000000007)

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

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
print(ans%(10**9+7))

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

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

for i in range(len(A)):
  if sum_A - A[i] < 0:
    sum_A = sum_A - A[i] + (10 ** 9 + 7)
  else:
    sum_A -= A[i]
  ans += A[i] * sum_A % (10 ** 9 + 7)

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

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

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

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

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

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

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

mod = 10**9+7

count = 0

num = sum(A) % mod

ans = 0
for a in A[:-1]:
    num = num-a
    ans = (ans+a*num) % mod

print(ans)

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

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

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
asum = sum(a)
ans = 0
mm = 1000000007
for i in a:
    asum -= i
    ll = i * (asum)
    ll = ll % mm
    ans += ll
    ans = ans % mm

print(ans)

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

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

print(ans)

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

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

res = 0
sumA = sum(A)
for i in range(N)[:-1]:
  sumA -= A[i]
  res += A[i] * sumA
  res %= MOD

print(res)

Solution (Python):
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque

if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')

def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())



n = int(input())
a = list(mapi())
b = a[:]
for i in range(n-2,-1,-1):
    b[i] += b[i+1]
res = 0
mod =  int(1e9+7)
for i in range(n-1):
    res = (res+a[i]*b[i+1]%mod)%mod
print(res)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
su=sum(a)
ru=[0 for i in range(n)]
ru[0]=su-a[0]

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

Solution (Python):

import math
import bisect
import copy
import time
from collections import Counter
from itertools import combinations


n=int(input())
l=[int(x) for x in input().split()]
ans=[0]*n
l=l[::-1]
ans[0]=l[0]
for i in range(1,n):
	ans[i]=l[i]+ans[i-1]
l=l[::-1]
c=0
M=10**9+7
ans=ans[::-1]
for i in range(1,n):
	c+=(ans[i]*l[i-1])%M
	c=c%M
print(c)

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

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

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

B = [0]*N

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

print(ans%1000000007)

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










s = sum(arr)
res = 0
for a in arr:
    s -= a
    res += a * s
    res %= mod

print(res)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
res = 0
S = sum(A)
for a in A:
    res += a * (S - a)
    S = (S - a)
print(res % 1000000007)

Solution (Python):
def modpow(a, n, mod):
    if n == 0:
        return 1
    else:
        if n % 2 == 0:
            return (modpow((a * a)%mod, n//2, mod)) % mod
        else:
            return ((a%mod) * modpow(a, n-1, mod)) % mod


def modinv(a, mod):
    return modpow(a, mod-2, mod) % mod

def moddiv(a, b, mod):
    return ((a%mod) * modinv(b, mod)) % mod


N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9+7
sumA = sum(A)
result = (sumA * sumA) % mod
for i in range(N):
    result = result - (A[i]*A[i])%mod
print(moddiv(result, 2, mod))

Solution (Python):
import sys


def input():
    return sys.stdin.readline().rstrip()

def main():

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

    ss =sum(A) %mod
    sm =ss *ss % mod
    for i in A:
        sm -= i*i
        sm %=mod

    sm =sm*pow(2,mod-2,mod) %mod

    print(int(sm))










if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().strip().split()))[:n]
sum=0 
sqsum=0
MOD=1000000007
for x in a:
    sum = sum+x
    sqsum = sqsum+ x*x

sum = sum*sum

ans = (sum-sqsum)//2
ans = ans%MOD
print(ans)

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

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

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

for i in range(n-1):
    counter=counter+a[i]*s[n-2-i]
    
if counter>10**9+7:
  counter=counter%(10**9+7)
print(counter)

Solution (Python):
from copy import deepcopy

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

B = deepcopy(A)

for i in range(N-1):
    B[i+1] += B[i]

ans = 0

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
MOD2INV = 5 * 10 ** 8 + 4
total = 0
delta = 0

for i in range(n):
  total = (total + a[i]) % MOD
  delta = ((a[i]%MOD) * (a[i]%MOD) + delta)%MOD

result = ((((total * total) - delta + MOD) % MOD) * MOD2INV)%MOD
print(result)

Solution (Python):

import sys
import numpy as np

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    sum_all = sum(A) % MOD
    ans = 0
    for i in range(N-1):
        ans = (ans + (A[i] * (sum_all-A[i]))) % MOD
        sum_all -= A[i]
    print(ans)
    return



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

if __name__ == '__main__':
    main()

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

Solution (Python):





"""
"""

from collections import defaultdict
from itertools import accumulate
import bisect

import sys
input = sys.stdin.readline

def solve(a):
    b = a.copy()
    b.reverse()
    c = list(accumulate(b))
    ans = 0
    modulo = 10**9 + 7
    n = len(a)
    for i, aa in enumerate(a[:-1]):
        cc = c[n-2-i] % modulo
        ans = (ans + (aa*cc%modulo))%modulo
    
    print(ans)

            

def main():
    _ = input()
    a = list(map(int,input().split()))
    solve(a)


if __name__ == "__main__":
    main()

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

Solution (Python):

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

As_sum = [As[0]]

for i in range(1, len(As)):
    As_sum.append((As_sum[-1]+As[i]) % MOD)

ans = 0
for i in range(len(As)-1, 0, -1):
    ans += As[i] * As_sum[i-1]
    ans %= MOD


print(ans % MOD)

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

S_n = 0
for a in A:
    S_n += a
    S_n %= MOD

a_i2 = 0
for a in A:
    a_i2 += a*a
    a_i2 %= MOD

d_ans = pow(S_n, 2 , MOD) - a_i2 + MOD
ans = (d_ans // 2) % MOD1
print(ans)

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

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

sum=[0]*n

sum[-1]=s[-1]

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

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

print(ans%(1000000007))

Solution (Python):
MOD = 10 ** 9 + 7
n = int(input())
s = list(map(int, input().split()))
acu = [0]
t = s[::-1]
for i in range(n):
    acu.append(acu[-1] + t[i])
u = acu[::-1]

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
S = [sum(A[1:])]
for a in A[1:-1]:
  S.append((S[-1]-a)%mod)

ans = 0
for a,s in zip(A,S):
  ans = (ans + a*s)%mod
print(ans)

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

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

sum_an = sum(an)
total = 0
for ai in an:
    total = total + ai * (sum_an - ai)
    sum_an = sum_an - ai
print(total % ((pow(10, 9) + 7)))

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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









MOD = 10**9+7

tot = sum(A)
tot %= MOD

ans = 0
rmv = 0

for a in A:
    rmv += a
    rmv %= MOD
    ans += a*(tot-rmv)
    ans %= MOD

print(ans)

Solution (Python):


n = int(input())
a_list = list(map(int, input().split()))
ans = 0
total = 0
mod = 10 ** 9 + 7
for i in range(n):
    total += a_list[i]
    if total >= mod:
        total = total % mod

for i in range(n - 1):
    total -= a_list[i]
    if total < 0:
        total += mod
    ans += a_list[i] * total
    if ans >= mod:
        ans = ans % mod
print(ans)

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

AA = sum(A)
ans = 0
mod = 10**9 + 7
for i in range(n):
    ans += (A[i] * (AA - A[i]))
print((ans // 2) % mod)

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

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

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

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

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

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

Ans = 0

sum_L = L[0]

l = len(L)

for i in L[1:]:
    Ans += sum_L*i%(10**9+7)
    sum_L += i
Ans = Ans%(10**9+7)
print(Ans)

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

print(sum)

Solution (Python):
def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  
  reversedIntegraA = [0] * len(A)
  reversedIntegraA[-1] = A[-1]
  base = 10**9+7

  for i in reversed(range(len(A) - 1)):
    reversedIntegraA[i] = reversedIntegraA[i+1] + A[i]

  result = 0
  for i in range(len(A) - 1):
    result += A[i] * reversedIntegraA[i+1]
    if result > base:
      result %= base
  print(result)


if __name__ == "__main__":
  resolve()

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

MOD = 10**9+7


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

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


if __name__ == '__main__':
    main(sys.stdin.readline, print)

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

modular=10**9+7
sum=0

AllSum=0
for i in range(N):
  AllSum+=A[i]
  AllSum=AllSum%modular

  
RuisekiWa=[]
NextSum=AllSum

for i in range(N):
  RuisekiWa.append((NextSum-A[i])%modular)
  NextSum=RuisekiWa[i]


for i in range(N):
  sum+=(A[i]*RuisekiWa[i])%modular
  sum=(sum%modular)
    
print(sum%modular)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    l = [A[0]]
    for i in range(N-2):
        l.append(l[-1] + A[i+1])

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

    print(ans % mod)


if __name__ == '__main__':
    main()

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
print(ans%mod)

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

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

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

Solution (Python):
mod = 1000000007
n = int(input())
A = [int(x) for x in input().split()]
cum = [0]
for a in A:
    cum.append((cum[-1] + a)%mod)


print(sum(A[i]*(cum[n] - cum[i+1])%mod for i in range(n))%mod)

Solution (Python):
import sys

input = sys.stdin.readline

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

A_sum_s = sum(A) ** 2

for e in A:
    A_sum_s -= e ** 2
print(A_sum_s // 2 % (10**9 + 7))

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

sum_arr = sum(arr)
sum_pow = 0

for a in arr:
  sum_pow = sum_pow + a*a

result = ((sum_arr*sum_arr) - sum_pow )//2 % mod

print(result)

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

MOD = 10 ** 9 + 7

res = 0
tmp = 0
for i in range(1, n):
    tmp += A[i - 1]
    res += A[i] * tmp
    res %= MOD

print(res)

Solution (Python):

import sys

MOD = 1000000007  


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

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

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



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

if __name__ == '__main__':
    main()