#coding UTF-8
N=int(input())
X=list(map(int,input().split()))
L=[0]*(N-1)
for i in range(N-1):
    L[i]=X[i+1]-X[i]
#print(L)

#累積和
W=[0]*(N-1)
W[0]=L[0]
for i in range(N-2):
    W[i+1]=L[i]+L[i+1]
#print(W)
R=[0]*(N-1)
R[0]=1
for i in range(N-2):
    R[i+1]=R[i]+1
ans=0
#print(R)
for i in range(N-1):
    ans+=W[i]*R[i]
print(ans%(10**9+7))