#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long n;
vector<long long> x;
int main() {
  cin >> n;
  x.resize(n);
  for (long long i = 0; i < (n); ++i) {
    cin >> x[i];
  }
  long long ans = 0;
  long long jud = 1;
  long long jud2 = 0;
  long long tmp = 0;
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = i + 1; j < n; j++) {
      ans += x[j] - x[i];
      ans %= MOD;
    }
  }
  cout << (ans) << endl;
}
