#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int IT_MAX = 1 << 17;
const long long MOD = 1000000007;
const int INF = 1034567890;
const long long LL_INF = 3234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;
long long in[1000050];
long long L[1000050];
long long R[1000050];
long long LR[1000050];
int main() {
  int N, i;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%lld", &in[i]), in[i]--;
  L[1] = in[1];
  for (i = 2; i <= N; i++) {
    L[i] = max(1ll, in[i] - in[i - 1] + 1);
    L[i] = in[i] - L[i] + 1;
  }
  R[N] = in[N];
  for (i = 1; i < N; i++) {
    R[i] = max(1ll, in[i] - in[i + 1] + 1);
    R[i] = in[i] - R[i] + 1;
  }
  for (i = 1; i <= N; i++) LR[i] = min(L[i], R[i]);
  for (i = 1; i <= N; i++) swap(L[i], R[i]);
  long long ans = 0, v = 0;
  for (i = 2; i <= N; i++) {
    v = (v * LR[i - 1] + L[i - 1]) % MOD;
    ans = (ans + R[i] * v) % MOD;
  }
  for (i = 1; i <= N; i++) ans = (ans + in[i]) % MOD;
  printf("%lld\n", ans);
  return 0;
}
