#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
struct edge {
  int to, cost;
};
int n, b, c;
vector<long long> a;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<long long> dp(100001, 0);
  for (int i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    a.push_back(temp);
  }
  long long sumt = 0;
  vector<long long> sum, sum1;
  for (int i = n - 1; i >= 1; i--) {
    sumt += a[i] - a[i - 1];
    sumt %= MOD;
    sum.push_back(sumt);
  }
  dp[2] = sum[0];
  int j = 1;
  for (int i = 0; i < n - 2; i++) {
    dp[i + 3] = dp[i + 2] + 2 * sum[j];
    dp[i + 3] %= MOD;
    j++;
  }
  cout << dp[n] << "\n";
}
