mod=10**9+7
N=int(input())
X=list(map(int,input().split()))
dist=[X[i+1]-X[i] for i in range(N-1)]

def kaijo(n):
    if n == 1:
        return n
    return (n*kaijo(n-1))%mod
f=kaijo(N-1)  
ans=0
for i in range(N-1):
  mi=0
  ans=(ans+dist[i]*((f+(i*2**((N-2)*(N-1)/2-1))%mod-mi)%mod))%mod
  mi+=i+1

print(int(ans))