#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr int MOD = 1'000'000'007;

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];

    VLL ru(n+1);
    REP(i,0,n) ru[i+1] = ru[i] + a[i];
    VVLL b(2, VLL(n));
    b[0][0] = 1;
    LL ans = 0;
    LL amul = 1;
    REP(i,1,n) {
        LL mul = 1;
        RREP(j,i+1,n) mul = (mul * j) % MOD;
        REP(j,0,i) {
            LL tmp = ((b[(i+1)%2][j] * mul) % MOD * (a[n-i+j] - a[n-i-1]) % MOD);
            ans += tmp;
            if (ans >= MOD) ans -= MOD;

            //cerr << i << ", " << j << ": " << tmp << "," << mul << endl;
        }
        int cnt = 0;
        if (i == 1) {
            b[i%2][0] = 0;
            b[i%2][1] = 1;
        } else {
            REP(j,0,i) {
                int sa = min(i-1, i - cnt % i);
                if (sa == 0) sa = i - 1;
                int sb = i - 1 - sa;
                b[i%2][j] = b[(i+1)%2][cnt/i] * sa + b[(i+1)%2][cnt/i+1] * sb;
                if (b[i%2][j] >= MOD) b[i%2][i] %= MOD;
            
                
                cnt += (i-1);
            }
            b[i%2][i] = ((b[(i+1)%2][i-1]) % MOD * i) % MOD;
        }
        b[i%2][0] = (b[i%2][0] + amul) % MOD;
        amul = (amul * (i+1)) % MOD;
    }
    cout << ans << endl;
    //dump("---");
    //dump(ans);
    //REP(i,0,n) cerr << b[0][i] << " ";
    //cerr << endl;
    //REP(i,0,n) cerr << b[1][i] << " ";
    //cerr << endl;
}

signed main() {
    solve();
    
    return 0;
}