#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10;
const long long Mod = 1e9 + 7;
long long a[MAXN];
long long b[MAXN];
long long dpa[MAXN];
long long dpb[MAXN];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n, res = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    if (i > 0) {
      b[i - 1] = min(a[i - 1], a[i]);
    }
  }
  dpa[0] = a[0];
  dpb[0] = b[0];
  for (long long i = 1; i < n; i++) {
    dpa[i] = a[i];
    if (a[i] >= a[i - 1]) {
      dpa[i] += (a[i - 1] * dpa[i - 1]) % Mod;
      dpa[i] %= Mod;
    } else {
      dpa[i] += (a[i] * dpb[i - 1]) % Mod;
      dpa[i] %= Mod;
    }
    dpb[i] = b[i];
    if (b[i] >= a[i - 1]) {
      dpb[i] += (a[i - 1] * dpa[i - 1]) % Mod;
      dpb[i] %= Mod;
    } else {
      dpb[i] += (b[i] * dpb[i - 1]) % Mod;
      dpb[i] %= Mod;
    }
  }
  for (long long i = 0; i < n; i++) {
    res += dpa[i];
    res %= Mod;
  }
  cout << res;
}
