Problem:
Score : 600 points

Problem Statement

There are N slimes standing on a number line.
The i-th slime from the left is at position x_i.

It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.

Niwango will perform N-1 operations. The i-th operation consists of the following procedures:

Choose an integer k between 1 and N-i (inclusive) with equal probability.

Move the k-th slime from the left, to the position of the neighboring slime to the right.

Fuse the two slimes at the same position into one slime.

Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.

Constraints

2 \leq N \leq 10^{5}

1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}

x_i is an integer.

Subtasks

400 points will be awarded for passing the test cases satisfying N \leq 2000.

Input

Input is given from Standard Input in the following format:

N
x_1 x_2 \ldots x_N

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

5

With probability \frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.

With probability \frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.

The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.

Sample Input 2

12
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932

Sample Output 2

750927044

Find the expected value multiplied by (N-1)!, modulo (10^9+7).

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	template<long long mod>
	class modint {
	private:
		long long a;
	public:
		constexpr modint(const long long x = 0) noexcept : a(x% mod) {}
		constexpr long long& value() noexcept { return a; }
		constexpr const long long& value() const noexcept { return a; }
		constexpr modint operator+(const modint rhs) const noexcept {
			return modint(*this) += rhs;
		}
		constexpr modint operator-(const modint rhs) const noexcept {
			return modint(*this) -= rhs;
		}
		constexpr modint operator*(const modint rhs) const noexcept {
			return modint(*this) *= rhs;
		}
		constexpr modint operator/(const modint rhs) const noexcept {
			return modint(*this) /= rhs;
		}
		constexpr modint& operator+=(const modint rhs) noexcept {
			a += rhs.a;
			if (a >= mod) a -= mod;
			return *this;
		}
		constexpr modint& operator-=(const modint rhs) noexcept {
			if (a < rhs.a) a += mod;
			a -= rhs.a;
			return *this;
		}
		constexpr modint& operator*=(const modint rhs) noexcept {
			a = a * rhs.a % mod;
			return *this;
		}
		constexpr modint& operator/=(modint rhs) noexcept {
			long long k = mod - 2;
			while (k > 0) {
				if (k & 1) {
					*this *= rhs;
				}
				rhs *= rhs;
				k /= 2;
			}
			return *this;
		}
		friend std::ostream& operator<<(std::ostream& os, const modint& X) {
			return os << X.a;
		}
		friend std::istream& operator>>(std::istream& is, modint& X) {
			is >> X.a;
			X.a %= mod;
			if (X.a < 0) X.a += mod;
			return is;
		}
	};

	using mint = modint<(int)1e9 + 7>;
}

int main() {

	ll n;
	std::cin >> n;
	std::vector<ll> x(n);
	rep(i, n) std::cin >> x[i];

	std::vector<mint> fact(n, 1);
	Rep(i, 2, n) {
		fact[i] = fact[i - 1] * i;
	}

	mint ans = 0;

	std::vector<mint> c(n);
	c[0] = fact[n - 1];
	for (int i = 0; i < n - 1; ++i) {
		// x[i + 1] - x[i] の距離を各スライムが移動する確率
		ll dist = x[i + 1] - x[i];

		ans += c[i] * dist;

		c[i + 1] = c[i] + fact[n - 1] / (i + 2);
	}

	std::cout << ans << std::endl;

	return 0;
}