#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;
int main() {
  uint N;
  cin >> N;
  vector<uint> x(N);
  for (uint i = 0; i < N; i++) cin >> x[i];
  ull mod = pow(10, 9) + 7;
  ull E = 0;
  for (uint i = 0; i < N - 1; i++) {
    E += (x[i + 1] - x[i]) * i;
    E %= mod;
    for (uint j = i + 1; j < N; j++) {
      E = E + x[j] - x[i];
      E %= mod;
    }
  }
  cout << E;
  return 0;
}
