You are given N slimes standing on a number line at positions x1, x2, ..., xN. Niwango will perform N-1 operations, each involving choosing an integer k between 1 and N-i, moving the k-th slime to the position of the neighboring slime to the right, and fusing the two slimes. Find the total distance traveled by the slimes multiplied by (N-1)!, modulo (10^9+7). The input format is N followed by x1, x2, ..., xN, and the output is the answer. For example, given N=3 and positions 1, 2, 3, the output is 5.

# Buggy version:
import math
N = int(input())
x = list(map(int, input().split()))
kyori = [x[i + 1] - x[i] for i in range(N - 1)]
MOD = 10 ** 9 + 7
kai = [0] * (N + 1)
kai[0] = 1
for i in range(1, N + 1):
    kai[i] = (kai[i - 1] * i) % MOD
c = [0] * N
c[0] = 1
for i in range(1, N):
    c[i] = c[i - 1] + (1 / (i + 1))
ans = 0
for i in range(N - 1):
    ans += (c[i] * kyori[i]) % MOD

print(ans * kai[N - 1] % MOD)

# Fixed version:
import math
N = int(input())
x = list(map(int, input().split()))
kyori = [x[i + 1] - x[i] for i in range(N - 1)]
MOD = 10 ** 9 + 7
kai = [0] * (N + 1)
kai[0] = 1
for i in range(1, N + 1):
    kai[i] = (kai[i - 1] * i) % MOD
c = [0] * N
c[0] = 0
for i in range(1, N):
    c[i] = ((kai[N - 1] * pow(i, MOD - 2, MOD) % MOD) + c[i - 1]) % MOD
ans = 0
for i in range(N - 1):
    ans = (ans + kyori[i] * c[i + 1] % MOD) % MOD

print(ans)

# Buggy version:
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
acum=[1]
for i in range(2,n+1):
  tmp=acum+pow(i,mod-2,mod)
  tmp%=mod
  acum.append(tmp)
ans=0
for i in range(n-1):
  ans+=(arr[i+1]-arr[i])*acum[i]
  ans%=mod
for i in range(1,n):
  ans*=i
  ans%=mod
print(ans)

# Fixed version:
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
acum=[0]
for i in range(1,n+1):
  tmp=acum[-1]+pow(i,mod-2,mod)*pow(i+1,mod-2,mod)
  tmp%=mod
  acum.append(tmp)
ans=0
for i in range(n-1):
  ans+=arr[i]*acum[i]
  ans%=mod
  ans-=arr[i]*acum[n-2-i]
  ans%=mod
  ans-=arr[i]*pow(n-1-i,mod-2,mod)
  ans%=mod
for i in range(1,n):
  ans+=arr[-1]*pow(i,mod-2,mod)
  ans%=mod
for i in range(1,n):
  ans*=i
  ans%=mod
print(ans)

# Buggy version:
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p

N = int(input())
A = [1 for _ in range(N+1)]
for i in range(2,N+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(N+1)]
B[N] = pow(A[N],p-2)
for i in range(N-1,1,-1):
    B[i] = (B[i+1]*(i+1))%p
X = list(map(int,input().split()))
X.insert(0,0)
C = [0 for i in range(N+1)]
C[1] = A[N-1]
for i in range(2,N):
    C[i] = (C[i-1]-A[N-1]*B[i])%p
C[N] = 0
for i in range(1,N):
    C[N] = (C[N]+C[i])%p
ans = (C[N]*X[N])%p
for i in range(1,N):
    ans = (ans-C[i]*X[i])%p
print(ans)

# Fixed version:
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
A = [1 for _ in range(N)]
for i in range(2,N):
    A[i] = (i*A[i-1])%p
X = list(map(int,input().split()))
X.insert(0,0)
cnt = 0
for i in range(1,N):
    cnt = (cnt+((X[N]-X[i])*pow(i,p-2))%p)%p
print((cnt*A[N-1])%p)

# Buggy version:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))
def mod_pow(x,n,mod):
    res = 1
    while(n > 0):
        if(n and 1):
            res = res * x % mod
        x = x * x % mod
        n >>= 1
    return res
prob = []
a = 0
for i in range(1,N):
    a += mod_pow(i,MOD-2,MOD)
    a %= MOD
    prob.append(a)
ans = 0
for i in range(1,N):

    """for j in range(1,i+1):
        prob += 1/j
    """
    ans += (x[i]-x[i-1]) * prob[i-1]
    ans %= MOD
for i in range(1,N):
    ans *= i
    ans %= MOD
ans = int(ans)
print(ans)

# Fixed version:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))
def mod_pow(x,n,mod):
    res = 1
    while(n > 0):
        if n&1:
            res = res * x % mod
        x = x * x % mod
        n >>= 1
    return res
prob = []
a = 0
for i in range(1,N):
    a += mod_pow(i,MOD-2,MOD)
    #koko
    a %= MOD
    prob.append(a)
ans = 0
for i in range(1,N):

    """for j in range(1,i+1):
        prob += 1/j
    """
    ans += (x[i]-x[i-1]) * prob[i-1]
    ans %= MOD

for i in range(1,N):
    ans *= i
    ans %= MOD
ans = int(ans)
print(ans)

# Buggy version:
import math
import sys 
input = sys.stdin.readline
N = int(input())
x = list(map(int,input().split()))

d = [0]*(N-1)
for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= 10**9+7

mod = 10**9+7
kaijou = 1
for i in range(1,N):
    kaijou *= i%mod
kaijou %= mod

ans=0
x=0

def pow_r(x, n):
    """
    O(log n)
    """
    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)**(10**9+5)を計算してyへ
    y = pow_r(i+1,k)
    #x+= kaijou//(i+1))%(10**9+7)
    x += (kaijou*y)%mod
    ans+= (d[i]*x)%mod

print(ans%mod)

# Fixed version:
import math
import sys 
input = sys.stdin.readline

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

d = [0]*(N-1)

for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod


kaijou = 1
for i in range(1,N):
    kaijou *= i
    kaijou %= mod


ans=0
x=0

def pow_r(x, n):
    """
    O(log n)
    """
    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

print(ans)

# Buggy version:
import statistics
import math

MOD = 10**9+7


def main():
    n = int(input())
    x = list(map(int, input().split()))

    c = 0
    t = 0
    for i in range(n-1):
        c += 1/(i+1)
        c %= MOD
        t += c * (x[i+1]-x[i])
        t %= MOD

    fact = math.factorial(n-1) % MOD
    print(t * fact % MOD)


main()


# Fixed version:
import statistics
import math

MOD = 10**9+7


def main():
    n = int(input())
    x = list(map(int, input().split()))

    c = 0
    t = 0
    for i in range(n-1):
        c += pow(i+1, MOD-2, MOD)
        t += c * (x[i+1]-x[i])
        t %= MOD

    fact = math.factorial(n-1) % MOD
    print(t * fact % MOD)


main()

# Buggy version:
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split()))) % MOD
L = np.cumsum(np.array([1 / x for x in range(1, n)])) % MOD
n_1 = factorial(n-1) % MOD

# fac = [1] * n
# for i in range(1,n):
# 	fac[i] = fac[i-1] * i % MOD

# print(int(np.sum(L * dist * n_1)) % MOD)
ans = 0
for l, d in zip(L, dist):
    ans += l * d
    ans %= MOD
print(ans * n_1 % MOD)
# print(int(np.sum(dist * L * n_1) % MOD))

# Fixed version:
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split())))
L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1) % MOD

# fac = [1] * n
# for i in range(1,n):
# 	fac[i] = fac[i-1] * i % MOD

# print(int(np.sum(L * dist * n_1)) % MOD)
# ans = 0
# for l, d in zip(L, dist):
#     print("l d ", l * d)
#     ans += l * d
#     ans %= MOD

ans = 0
tmp = 0
for i, d in enumerate(dist):
    tmp += pow(i+1, MOD-2, MOD)
    ans += tmp * d
    ans %= MOD

# print(n_1)
print(ans * n_1 % MOD)
# print(int(np.sum(dist * L * n_1) % MOD))

# Buggy version:
import math

mod = 10**9 + 7

n = int(input())
x = list(map(int,input().split()))
dis = [x[i]-x[i-1] for i in range(1,n)]


f = math.factorial(n-1)
f %= mod

def modinv(a, mod=mod):
    return pow(a, mod-2, mod)
inv2 = modinv(2)

count = 0
for i in range(1,n):
    e = (i+1)*inv2%mod
    count = (count + e*dis[i-1])%mod
count = count*f%mod

print(int(count)%mod)


# Fixed version:
import math

mod = 10**9 + 7

n = int(input())
x = list(map(int,input().split()))
dis = [x[i]-x[i-1] for i in range(1,n)]
f = (math.factorial(n-1))%mod
def modinv(a, mod=mod):
    return pow(a, mod-2, mod)

count = 0
suminv = 0
for i in range(1,n):
    suminv += modinv(i)
    suminv %= mod
    count += dis[i-1]*suminv
    count %= mod
count = (count*f)%mod

print(int(count))

# Buggy version:
n = int(input())
l = list(map(int,input().split()))
sa = []
for i in range(n-1):
    sa.append(l[i+1]-l[i])

mod = 10**9+7
ans = 0
count = 0
kai = 1

    
for i in range(n-1):
    count += 1/(i+1)
    
    
    ans += sa[i]*count
    ans %= mod
for i in range(n-1):
    ans *= (i+1)
    ans %= mod

print(int(ans%mod))


# Fixed version:
n = int(input())
l = list(map(int,input().split()))
sa = []
for i in range(n-1):
    sa.append(l[i+1]-l[i])

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


print(int(kai*ans%mod))

# Buggy version:
n = int(input())
x = list(map(int, input().split()))

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

ans = 0
j_inv = []
num = 0
for j in range(1, n):
    num += inv[j]
    num %= mod
    j_inv.append(num)

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

ans *=fac[n-1]
ans %= mod

print(ans)



# Fixed version:
n = int(input())
x = list(map(int, input().split()))

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

ans = 0
j_inv = []
num = 0
for j in range(1, n):
    num += inv[j]
    num %= mod
    j_inv.append(num)

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

ans *=fac[n-1]
ans %= mod

print(ans)

# Buggy version:
N = int(input())
X = list(map(int,input().split()))
import math
ans = 0
mod = 10**9+7
a = 0
ans = 0
for i in range(N-1):
  a += 1/(i+1)
  ans += (X[i+1]-X[i])%mod*a

ans *= math.factorial(N-1)%mod
print(int(ans)%mod)

# Fixed version:
N = int(input())
X = list(map(int,input().split()))
import math
ans = 0
mod = 10**9+7
a = 0
ans = 0
for i in range(N-1):
  a += pow(i+1,mod-2,mod)
  ans += ((X[i+1]-X[i])%mod)*(a%mod)
  ans %= mod
  
ans *= math.factorial(N-1)%mod

print(ans%mod)

# Buggy version:
from math import factorial
 
N = int(input())
x = list(map(int, input().split()))
mod = 10**9 + 7
x_dis = [x[i+1] - x[i] for i in range(N-1)]
ans = 0
m = N-1
fac = factorial(m) % mod
tmp = fac
for i in range(m):
    ans += x_dis[i] * tmp
    ans %= mod
print(ans)

# Fixed version:
from math import factorial

N = int(input())
x = list(map(int, input().split()))
mod = 10**9 + 7
x_dis = [x[i+1] - x[i] for i in range(N-1)]
ans = 0
m = N-1
fac = factorial(m) % mod
tmp = fac
for i in range(m):
    ans += x_dis[i] * tmp
    ans %= mod
    tmp += (fac*pow((i+2),(mod-2), mod))%mod
print(ans)

# Buggy version:
import sys
input = sys.stdin.readline
N = int(input())
x = list(map(int, input().split()))
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod

f = Factorial(N, mod)
dp = [0] * N
res = 0
for i in range(N - 2):
  for j in range(i + 1, N):
    t = f.combi(N - 1, min(j - i + 1 - (j == N - 1), N - 1)) * f.factorial(j - i - 1) % mod
    #print(i, j, t)
    #t *= f.factorial(N - 1) * f.ifactorial(t) % mod
    #print(i, j, t)
    dp[i] += t * (x[j] - x[i])
    dp[i] %= mod
dp[N - 2] = f.factorial(N - 1) * (x[-1] - x[-2]) % mod
for i in range(N):
  res += dp[i]
  res %= mod
print(res)

# Fixed version:
import sys
input = sys.stdin.readline
N = int(input())
x = list(map(int, input().split()))
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod

f = Factorial(N, mod)
res = 0
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] * (i + 1) + f.factorial(i) % mod
  t[i + 1] %= mod
#print(t)
for i in range(N - 2, -1, -1):
  res += (x[i + 1] - x[i]) * t[i + 1] * f.factorial(N - 1) % mod * f.ifactorial(i + 1) % mod
  res %= mod
print(res)

# Buggy version:
N=int(input())
X=list(map(int,input().split()))
MOD=10**9+7

facN_1=1
for i in range(2,N):
    facN_1*=i

P=[0]*N
for i in range(1,N):
    P[i]=facN_1//i

ans=0
for i in range(N-1):
    tmp=X[i+1]-X[i]
    tmp*=(i+1)*(i+2)//2
    tmp*=P[i+1]%MOD
    ans+=tmp
    ans%=MOD
print(ans)

# Fixed version:
N=int(input())
X=list(map(int,input().split()))
MOD=10**9+7

facN_1=1
suminv=[1]*N
inv=[1]*N
for i in range(2,N):
    facN_1=facN_1*i%MOD
    inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
    suminv[i]=(suminv[i-1]+inv[i])%MOD

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

# Buggy version:
n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = n
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)


# Fixed version:
n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = n+2
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)

# Buggy version:
N = int(input())
A = list(map(int, input().split()))
mod = 1e+9 + 7
p = mod - 2
S = []
while p != 0:
  S = [p%2] + S[:]
  p //= 2
frac = 1
for i in range(N - 1):
  frac *= i+1
  frac %= mod
T = 0
for i in range(N - 1):
  k = 1
  for j in range(len(S)):
    if S[j] == 1:
      k *= i+1
      k %= mod
    if j != len(S) - 1:
      k *= k
      k %= mod
  T += (frac * k * (A[N - 1] - A[i])) % mod
  T %= mod
print(T%mod)

# Fixed version:
N = int(input())
A = list(map(int, input().split()))
mod = int(1e+9 + 7)
p = mod - 2
S = []
while p != 0:
  S = [p%2] + S[:]
  p //= 2
frac = 1
for i in range(N - 1):
  frac *= i+1
  frac %= mod
T = 0
for i in range(N - 1):
  k = 1
  for j in range(len(S)):
    if S[j] == 1:
      k *= i+1
      k %= mod
    if j != len(S) - 1:
      k *= k
      k %= mod
  T += (frac * k * (A[N - 1] - A[i])) % mod
  T %= mod
print(T%mod)

# Buggy version:
import sys
sys.setrecursionlimit(10**6)


def mod_inverse(n, mod=10**9+7):
    return pow(n, mod-2, mod)


def combination(n, k, mod=10**9+7):
    numer = denom = 1
    for i in range(k):
        numer = (numer * (n-i)) % mod
        denom = (denom * (i+1)) % mod
    return (numer * mod_inverse(denom, mod)) % mod


def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1) % mod


mod = 10**9+7
N = int(input())
x = [0] + list(map(int, input().split()))

ans = 0
for k in range(2, N):
    ans = (ans + x[k] * (1 - mod_inverse(k))) % mod

for k in range(1, N-1):
    ans = (ans - x[k] * (1 - mod_inverse(N-k))) % mod

ans = (ans + sum((x[N] - x[k]) * mod_inverse(N-k) for k in range(1, N))) % mod

ans = ans * factorial(N-1) * mod

print(ans)


# Fixed version:
import sys
sys.setrecursionlimit(10**6)


def mod_inverse(n, mod=10**9+7):
    return pow(n, mod-2, mod)


def combination(n, k, mod=10**9+7):
    numer = denom = 1
    for i in range(k):
        numer = (numer * (n-i)) % mod
        denom = (denom * (i+1)) % mod
    return (numer * mod_inverse(denom, mod)) % mod


def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1) % mod


mod = 10**9+7
N = int(input())
x = [0] + list(map(int, input().split()))
fact = factorial(N-1)

ans = 0
for k in range(2, N):
    ans = (ans + x[k] * (1 - mod_inverse(k)))

for k in range(1, N-1):
    ans = (ans - x[k] * (1 - mod_inverse(N-k))) % mod

ans = ans * fact % mod

ans = (ans + fact * sum((x[N] - x[k]) * mod_inverse(N-k) for k in range(1, N))) % mod

print(ans)

# Buggy version:
import sys
input = sys.stdin.readline
n = int(input())

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

mod = 10**9 + 7

li = []
for i in range(n-1):
    li.append(x[i+1] - x[i])

dp = [0] * (n-1)
dp2 = [0] * (n-1)
dp3 = [0] * n
dp3[0] = 1

for i in range(n-1):
    dp3[i+1] = dp3[i] * (i+2)

dp[0] = x[1] - x[0]
dp2[0] = 1

for i in range(n-2):
    dp2[i+1] = dp2[i] * (i+2) + dp3[i]

ans = 0

for i in range(n-2):
    print(dp[i] * (i+2),(x[i+2] - x[i+1]) * dp3[i+1])
    dp[i+1] = dp[i] * (i+2) + (x[i+2] - x[i+1]) * dp2[i+1]
    dp[i+1] %= mod

print(dp[-1] % mod)


# Fixed version:
import sys
input = sys.stdin.readline
n = int(input())
x = list(map(int,input().split()))

#n = 10**5
#x = list(range(10**5))
mod = 10**9 + 7

li = []
for i in range(n-1):
    li.append(x[i+1] - x[i])

dp = [0] * (n-1)
dp2 = [0] * (n-1)
dp3 = [0] * n
dp3[0] = 1

for i in range(n-1):
    dp3[i+1] = dp3[i] * (i+2)
    dp3[i+1] %= mod

dp[0] = x[1] - x[0]
dp2[0] = 1

for i in range(n-2):
    dp2[i+1] = dp2[i] * (i+2) + dp3[i]
    dp2[i+1] %= mod
ans = 0
for i in range(n-2):
    dp[i+1] = dp[i] * (i+2) + (x[i+2] - x[i+1]) * dp2[i+1]
    dp[i+1] %= mod

print(dp[-1] % mod)