#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int x[100100];
  int c[100100];
  cin >> N;
  for (int i = 1; i < N + 1; i++) cin >> x[i];
  c[N - 1] = N - 2;
  c[N - 2] = N - 1;
  long long int sum = (N - 1) + (N - 2);
  for (int i = N - 3; i > 0; i--) {
    c[i] = c[i + 2] * c[i + 1];
    sum += c[i];
  }
  int ans = (sum * x[N]) % (1000000000 + 7);
  for (int i = 1; i < N; i++) {
    ans -= (c[i] * x[i]) % (1000000000 + 7);
  }
  cout << ans << endl;
}
