CodeEff/ECCO huggingface dataset:
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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 LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
X = LI()
d = [0] * (n - 1)
for i in range(n - 1):
    d[i] = X[i + 1] - X[i]


fac = factorial(n - 1)


acc = list(accumulate([fac // i for i in range(1, n)]))
ret = 0
for j in range(n - 1):
    ret += acc[j] * d[j]


print((ret % mod))











# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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 LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
X = LI()
d = [0] * (n - 1)
for i in range(n - 1):
    d[i] = (X[i + 1] - X[i]) % mod



fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod



for i in range(1, n):
    inv[i] = pow(i, mod - 2, mod)




L = [fac[n - 1] * inv[i] % mod for i in range(1, n)]
for k in range(1, n - 1):
    L[k] = (L[k] + L[k - 1]) % mod




ret = 0
for j in range(n - 1):
    ret = (ret + L[j] * d[j] % mod) % mod


print((ret % mod))
# Original solution
N = int(eval(input()))
A = [int(a) for a in input().split()]
    
if N > 2000:
  print((0))
  
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

import math

ans = 0
for i in range(1, N):
    ans += cmb(N-1, N-i, mod)*math.factorial(i-1)*math.factorial(N-i-1)*(A[N-1]-A[i-1])
    ans %= mod
    for j in range(i+1, N):
        ans += cmb(N-1, j-i+1, mod)*math.factorial(N-j+i-2)*math.factorial(j-i-1)*(A[j-1]-A[i-1])
        ans %= mod
        
print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(a) for a in input().split()]
    
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

S = [0]*N
for i in range(N-1):
    S[i+1] = S[i] + L2[i]
    
L3 = [0]*N
for i in range(1, N):
    if N-i-1 >= i:
        L3[i] = L3[i-1] + S[N-i-1] - S[i-1]
    else:
        L3[i] = L3[N-i-1]

for t in range(1, N-1):
    ans += cmb(N-1, t+1, mod)*L[N-t-2]*L[t-1]*L3[t]
    ans %= mod
        
print(ans)
# Original solution
N = int(eval(input()))
x = list(map(int, input().split()))

mod = 10 ** 9 + 7
f = [1]
for i in range(1,N+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod

ans = 0
l = [0] + [(((comb(N-1,2+i) * f[N-(3+i)]) % mod) * f[i]) % mod for i in range(N-2)] + [f[N-2]]


for i in range(N-1):
    for j in range(i+1,N):
        ans += (l[j-i] * (x[j] - x[i])) % mod
        ans %= mod
        if j == N - 1:
            l[j-i-1] = l[j-i-1] + l[j-i]

print(ans)

# Optimized solution
N = int(eval(input()))
x = list(map(int, input().split()))

mod = 10 ** 9 + 7

c = [1]
for i in range(1,N-1):
    c.append(c[i-1]+pow(i+1,mod-2,mod))

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

print(ans)
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
r = 10 ** 9 + 7
a = [1]
p = 1
for i in range(1, n - 1):
    p *= i
    q = p + a[0] * (i + 1)
    a = [q] + a

ans = (x[n - 1] - x[n - 2]) * a[0]
ans %= r
k = n - 1
for i in range(2, n):
    ans += (x[n - i] - x[n - i - 1]) * a[i - 1] * k
    ans %= r
    k *= n - i

print(ans)

# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))
r = 10 ** 9 + 7
p = 1
for i in range(1,n):
    p *= i
f = x[n - 1]
ans = 0

for i in range(n-1):
    ans += (f - x[i]) * p
    ans %= r
    p = p * (i + 1) // (i + 2)

print(ans)
# Original solution
N = int(eval(input()))
X = list(map(int,input().split()))
S = []
dp = [1]
mod = 10**9+7
for i in range(N):
    t = i+1
    dp.append(dp[i]*t)
W = []
for i in range(1,N):
    y = dp[N-1]//i
    y % mod
    W.append(y)
ans = 0
for i in range(N-1):
    x = X[i]
    S.append(X[N-1]-x)
ans = 0
for i in range(N-1):
    x = S[i]
    t = i + 1
    ans += W[i]*x%mod
print((ans%mod))

# Optimized solution
N = int(eval(input()))
X = list(map(int,input().split()))
S = []
dp = [1]
mod = 10**9+7
for i in range(N):
    t = i+1
    dp.append(dp[i]*t%mod)
def power(a,b):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power(a,b//2)
        return d*d%mod
    elif b % 2 == 1:
        return a*power(a,b-1)%mod
W = []
for i in range(1,N):
    y = dp[N-1]*power(i,mod-2)%mod
    W.append(y)
ans = 0
for i in range(N-1):
    x = X[i]
    S.append(X[N-1]-x)
ans = 0
for i in range(N-1):
    x = S[i]
    t = i + 1
    ans += W[i]*x%mod
print((ans%mod))
# Original solution
import sys
input = sys.stdin.readline
from fractions import Fraction

def main(): 
    N = int(eval(input()))
    x = [int(i) for i in input().split()]

    MOD = 10**9+7

    answer = 0
    frac = 0
    for i in range(N-1):
        frac += Fraction(1,i+1)
        dist = (x[i+1] - x[i]) % MOD
        answer = (answer + dist * frac) % MOD
    for i in range(1,N):
        answer = (answer * i) % MOD

    print((int(answer)))

if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline

# 1~nまでの逆元(mod m) O(n)
def mod_inv_list(n:int, m:int):
    # inv_t[i]: iの法mの下での逆元
    inv_t = [0] + [1]
    for i in range(2,n):
        inv_t += [inv_t[m % i] * (m - m//i) % m]
    return inv_t

def main():
    N = int(eval(input()))
    x = [int(i) for i in input().split()]
    MOD = 10**9 + 7

    inv_acum = mod_inv_list(N,MOD)
    for i in range(1,N):
        inv_acum[i] = (inv_acum[i] + inv_acum[i-1]) % MOD

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

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

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
from functools import reduce
# https://atcoder.jp/contests/dwacon6th-prelims/submissions/9425560
# 部分点解法

def main():
    from functools import reduce

    MOD = 10 ** 9 + 7

    n = int(eval(input()))
    *x, = list(map(int, input().split()))

    fact = [1]
    for i in range(1, n + 1):
        fact.append(fact[-1] * i)

    dist_to_r_edge = [x[-1] - x_ for x_ in x[:-1]]

    ret = reduce(
        lambda a, b: (a + b) % MOD,
        (
            d * pow(i, MOD - 2, MOD)
            for i, d in enumerate(dist_to_r_edge, 1)
        )
    )
    print((ret * fact[n - 1] % MOD))


if __name__ == '__main__':
    main()

# ret = 0
# for i, d in enumerate(dist_to_r_edge, 1):
#     ret = (ret + d * pow(i, MOD - 2, MOD)) % MOD
# print(ret * fact[n - 1] % MOD)


# Optimized solution
from functools import reduce
# 部分点

def main():
    from functools import reduce

    MOD = 10 ** 9 + 7

    n = int(eval(input()))
    *x, r = list(map(int, input().split()))

    dist_to_r_edge = [r - x_ for x_ in x]

    ret = reduce(
        lambda a, b: (a + b) % MOD,
        (
            d * pow(i, MOD - 2, MOD)
            for i, d in enumerate(dist_to_r_edge, 1)
        )
    )

    f = 1
    for i in range(1, n):
        f = (f * i) % MOD

    print((ret * f % MOD))


if __name__ == '__main__':
    main()
# Original solution
from functools import reduce
# 部分点

def main():
    from functools import reduce

    MOD = 10 ** 9 + 7

    n = int(eval(input()))
    *x, r = list(map(int, input().split()))

    dist_to_r_edge = [r - x_ for x_ in x]

    ret = reduce(
        lambda a, b: (a + b) % MOD,
        (
            d * pow(i, MOD - 2, MOD)
            for i, d in enumerate(dist_to_r_edge, 1)
        )
    )

    f = 1
    for i in range(1, n):
        f = (f * i) % MOD

    print((ret * f % MOD))


if __name__ == '__main__':
    main()


# Optimized solution
from functools import reduce
def build_cumsum_invs(ub, mod):
    ret = [0]
    t = 0
    for i in range(1, ub + 1):
        t = (t + pow(i, mod - 2, mod)) % mod
        ret.append(t)
    return ret


def main():
    from functools import reduce

    MOD = 10 ** 9 + 7

    n = int(eval(input()))
    *x, = list(map(int, input().split()))

    coef = build_cumsum_invs(ub=n, mod=MOD)
    # <---><---><---><---><--->
    # x1/1  1/2  1/3  1/4  1/5
    #      x1/1  1/2  1/3  1/4
    #           x1/1  1/2  1/3
    # x点から移動開始したスライムが区間を通過する確率
    # 縦に和をとると、逆数の累積和coefになっている

    prob = reduce(
        lambda a, b: (a + b) % MOD,
        (
            (x[i] - x[i - 1]) * coef[i]
            for i in range(1, n)
        )
    )

    f = reduce(
        lambda a, b: a * b % MOD,
        list(range(1, n))
    )

    print(((prob * f) % MOD))


if __name__ == '__main__':
    main()

# prob = 0
# for i in range(1, n):
#     prob = (prob + (x[i] - x[i - 1]) * coef[i]) % MOD
# ret = (prob * reduce(lambda a, b: a * b % MOD, range(1, n))) % MOD
# print(ret)
# Original solution
import math
import sys 
input = sys.stdin.readline
N = int(eval(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


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

#kaijou = math.factorial(N-1)%(10**9+7)
ans=0
x=0
k=10**9+5

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

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)%(10**9+7)
    ans+= d[i]*x

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


# Optimized solution
import math
import sys 
input = sys.stdin.readline

N = int(eval(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)
# Original solution
import math
import sys 
input = sys.stdin.readline

N = int(eval(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 #これをしないとkaijouが発散


ans=0
x=0

def pow_a(a,n): #(modを取るように改良)
    if n==0:
        return 1
    
    K = 1
    while n>1:
        if n%2 != 0:
            K *= a
            K %= mod
        a *= a
        a %= mod
        n //= 2

    return K*a

for i in range(N-1):
    y = pow_a(i+1,mod-2) #i+1の逆元
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

print(ans)


# Optimized solution
import math
import sys 
input = sys.stdin.readline

N = int(eval(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):
    i %= mod
    kaijou *= i
    kaijou %= mod #これをしないとkaijouが発散


ans=0
x=0

def pow_a(a,n): #(modを取るように改良)
    if n==0:
        return 1
    
    K = 1
    while n>1:
        if n%2 != 0:
            K *= a
            K %= mod
        a *= a
        a %= mod
        n //= 2

    return (K*a)%mod

for i in range(N-1):
    y = pow_a(i+1,mod-2) #i+1の逆元
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

print(ans)
# Original solution
import math

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

fac = math.factorial(n - 1)


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


res = 0
for i in range(n - 1):
    d = x[n - 1] - x[i]
    res += (d * fac * pow(i + 1, mod - 2)) % mod

print((res % mod))


# Optimized solution
import math

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

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


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


res = 0
for i in range(n - 1):
    d = x[n - 1] - x[i]
    res += (d * fac * pow(i + 1, mod - 2)) % mod

print((res % mod))
# Original solution
import sys
from itertools import count, accumulate
from operator import mul
from functools import reduce
lines = sys.stdin.readlines()

positions = [int(i) for i in lines[1].split(' ')]

distances = [ j - i for i, j in zip(positions, positions[1:])]

n = len(distances)
factorials = [1] + list(accumulate(list(range(1,n + 1)), mul))

combinations = dict()
def combination(i, j):
    if (i, j) in combinations:
        return combinations((i, j))
    else:
        return factorials[i] // (factorials [j] * factorials[i - j])

permutations = dict()
def permutation(i, j):
    if (i, j) in permutations:
        return permutations((i, j))
    else:
        return reduce(mul, list(range(j, i+1)))

s = 0
result = 0
for d, i in zip(distances, count(1)):
    lt = i - 1
    gt = n - i
    t = factorials[lt] * combination(n, gt) * factorials[gt]
    s += t
    result += d * s

print((int(result % (pow(10,9) + 7))))

# Optimized solution
import sys
from itertools import count, accumulate
from operator import mul
from functools import reduce
lines = sys.stdin.readlines()

positions = [int(i) for i in lines[1].split(' ')]

distances = [ j - i for i, j in zip(positions, positions[1:])]

n = len(distances)
factorials = [1] + list(accumulate(list(range(1,n + 1)), mul))

combinations = dict()
def combination(i, j):
    j = min(j, i - j)
    if (i, j) in combinations:
        return combinations((i, j))
    else:
        return factorials[i] // (factorials [j] * factorials[i - j])

permutations = dict()
def permutation(i, j):
    if (i, j) in permutations:
        return permutations((i, j))
    else:
        return reduce(mul, list(range(j, i+1)))

s = 0
result = 0
for d, i in zip(distances, count(1)):
    lt = i - 1
    gt = n - i
    t = factorials[lt] * combination(n, gt) * factorials[gt]
    s += t
    result += d * s

print((int(result % (pow(10,9) + 7))))
# Original solution
import sys
from itertools import count, accumulate
from operator import mul
from functools import reduce
lines = sys.stdin.readlines()

positions = [int(i) for i in lines[1].split(' ')]

distances = [ j - i for i, j in zip(positions, positions[1:])]

n = len(distances)
factorials = [1] + list(accumulate(list(range(1,n + 1)), mul))

combinations = dict()
def combination(i, j):
    j = min(j, i - j)
    if (i, j) in combinations:
        return combinations((i, j))
    else:
        return factorials[i] // (factorials [j] * factorials[i - j])

permutations = dict()
def permutation(i, j):
    if (i, j) in permutations:
        return permutations((i, j))
    else:
        return reduce(mul, list(range(j, i+1)))

s = 0
result = 0
for d, i in zip(distances, count(1)):
    lt = i - 1
    gt = n - i
    t = factorials[n] // i
    s += t
    result += d * s

print((int(result % (pow(10,9) + 7))))

# Optimized solution
import sys
from itertools import count, accumulate
from operator import mul
from functools import reduce
lines = sys.stdin.readlines()

positions = [int(i) for i in lines[1].split(' ')]

distances = [ j - i for i, j in zip(positions, positions[1:])]

n = len(distances)
p = pow(10,9) + 7

factorials = [1] + list(accumulate(list(range(1,n + 1)), lambda x, y: (x * y) % p))

combinations = dict()
def combination(i, j):
    j = min(j, i - j)
    if (i, j) in combinations:
        return combinations((i, j))
    else:
        return factorials[i] // (factorials [j] * factorials[i - j])

permutations = dict()
def permutation(i, j):
    if (i, j) in permutations:
        return permutations((i, j))
    else:
        return reduce(mul, list(range(j, i+1)))

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n = n >> 1
    return res

s = 0
result = 0
for d, i in zip(distances, count(1)):
    lt = i - 1
    gt = n - i
    i_inv = modpow(i, p-2, p)
    t = factorials[n] * i_inv
    s += t
    result += d * s

print((int(result % (pow(10,9) + 7))))
# Original solution
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 510000
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

N = int(eval(input()))
X = list(map(int, input().split()))
# expected_value = [1]
# for i in range(2, N):
#     expected_value.append(expected_value[-1]+(1/i))
ans = 0
f = factrial[N-1]
c = 0
for i in range(1, N):
    c += f * inverse[i]
    c %= MOD
    ans += c * (X[i] - X[i-1])
    ans %= MOD

print((ans % MOD))


# Optimized solution
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 100005
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

N = int(eval(input()))
X = list(map(int, input().split()))

ans = 0
prepro = [1]
for i in range(2, N+1):
    prepro.append((prepro[-1]+inverse[i]) % MOD)

for i in range(N-1):
    ans += (X[i+1]-X[i]) * prepro[i] % MOD

ans *= factrial[N-1]  # 期待値の総和に(N-1)!をかける

print((ans % MOD))
# Original solution
n = int(eval(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
for i in range(1, n):
    base *= i
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b // (i + 2)
    base % mod
print(ans)


# Optimized solution
n = int(eval(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)
# Original solution
MOD = 10**9+7
n = int(eval(input()))
F = [1]*(n+1)
for i in range(n):
  F[i+1] = F[i]*(i+1) % MOD
X = list(map(int, input().split()))
D = [X[i+1]-X[i] for i in range(n-1)]
T = [1]*n
for i in range(2, n):
  T[i] = T[i-1]*i+F[i-1]
  T[i] %= MOD
t = 1
for i in range(1, n-1):
  t *= (n-i) % MOD
  T[n-1-i] *= t % MOD
ans = 0
for i in range(1, n):
  ans += D[i-1]*T[i]
  ans %= MOD
print(ans)

# Optimized solution
MOD = 10**9+7
n = int(eval(input()))
F = [1]*(n+1)
for i in range(n):
  F[i+1] = F[i]*(i+1)
  F[i+1] %= MOD
X = list(map(int, input().split()))
D = [X[i+1]-X[i] for i in range(n-1)]
T = [1]*n
for i in range(2, n):
  T[i] = T[i-1]*i+F[i-1]
  T[i] %= MOD
t = 1
for i in range(1, n-1):
  t *= (n-i)
  t %= MOD
  T[n-1-i] *= t
  T[n-1-i] %= MOD
ans = 0
for i in range(1, n):
  ans += D[i-1]*T[i]
  ans %= MOD
print(ans)
# Original solution
N = int(eval(input()))
X = list(map(int,input().split()))
MOD = 10**9+7

MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

c = 0
f = fac[N-1]
ans = 0
for i in range(1,N):
    c += f * inv[i]
    c %= MOD
    ans += c * (X[i] - X[i-1])
    ans %= MOD
print(ans)


# Optimized solution
N = int(eval(input()))
X = list(map(int,input().split()))
Y = [b-a for a,b in zip(X,X[1:])]

MOD = 10**9+7
MAXN = N+5
fac = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD

ans = m = 0
for i,y in enumerate(Y):
    m += fac[N-1] * inv[i+1]
    ans += y*m
    ans %= MOD
print(ans)