#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 7;
const long long mof = 1e9 + 7;
int n;
long long dat[maxn];
long long h1[maxn], hx[maxn], x[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> dat[i], dat[i]--;
  hx[n] = dat[n];
  x[n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    if (dat[i] >= dat[i + 1]) {
      x[i] = (h1[i + 1] + hx[i + 1] * x[i + 1] + 1) % mof;
      hx[i] = dat[i + 1];
      h1[i] = dat[i] - dat[i + 1];
    } else if (dat[i] <= hx[i + 1]) {
      x[i] = (dat[i] * x[i + 1] + 1) % mof;
      hx[i] = dat[i];
    } else {
      x[i] = (hx[i + 1] * x[i + 1] + dat[i] - hx[i + 1] + 1) % mof;
      hx[i] = dat[i];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans = (ans + h1[i] + hx[i] * x[i]) % mof;
  cout << ans << endl;
}
