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: Time Limit Exceeded)

#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

template<std::uint_fast64_t Mod>
struct modint{
  using u64=int_fast64_t;
  u64 a;
  constexpr modint(const u64 x=0) noexcept:a(x%Mod){}
  constexpr u64 &value() noexcept{return a;}
  constexpr const u64 &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{
    u64 exp=Mod-2;
    while(exp){
      if(exp%2)*this*=rhs;
      rhs*=rhs;
      exp/=2;
    }
    return *this;
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin>>N;
  vector<ll>x(N);
  for(int i=0;i<N;i++)cin>>x[i];
  vector<modint<MOD>>f(N);
  f[0]=f[1]=1;
  for(int i=2;i<N;i++)f[i]=f[i-1]*(i%MOD);
  modint<MOD>ans=0;
  for(int i=0;i<N-1;i++){
    modint<MOD>C=0;
    for(int j=1;j<=i+1;j++){
      C+=modint<MOD>(1)/modint<MOD>(j);
    }
    ans+=modint<MOD>(x[i+1]-x[i])*C;
  }
  ans*=f[N-1];
  cout<<ans.a<<endl;

  return 0;
}