#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, ans = 0, tmp = 0, mod = 1e9 + 7;
  cin >> N;
  vector<long long> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  if (N == 2) {
    ans = X.at(1) % mod - X.at(0) % mod;
  } else if (N == 3) {
    ans = N * X.at(2) % mod - X.at(1) % mod - (N - 1) * X.at(0) % mod;
  } else {
    ans += (3 * N - 1) * X.at(N - 1) % mod;
    ans %= mod;
    for (int i = 1; i < N - 1; i++) {
      tmp -= (i + 1) * X.at(N - i - 1) % mod;
      tmp %= mod;
    }
    tmp -= (N + 2) * X.at(0) % mod;
    ans += tmp;
  }
  cout << ans % mod << endl;
}
