#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const long long INFL = (1LL << 60);
int main() {
  int n;
  cin >> n;
  vector<long long> a(n), x(n);
  for (int x_i = 0; x_i < (n); ++x_i) cin >> a[x_i];
  for (int i = (1); i < (n); ++i) x[i - 1] = a[n - 1] - a[n - 1 - i];
  vector<long long> dp(n, 0);
  long long ans = 0;
  dp[0] = x[0];
  for (int i = (1); i < (n - 1); ++i) {
    dp[i] = (x[i] - x[i - 1]) + dp[i - 1];
    dp[i] += x[i] + dp[i - 1];
    dp[i] %= MOD;
  }
  for (int x_i = 0; x_i < (n - 1); ++x_i)
    cerr << x[x_i] << " \n"[x_i == n - 1 - 1];
  for (int x_i = 0; x_i < (n - 1); ++x_i)
    cerr << dp[x_i] << " \n"[x_i == n - 1 - 1];
  cout << dp[n - 2] << endl;
  return 0;
}
