#include <bits/stdc++.h>
using namespace std;
struct _ {
  ios_base::Init i;
  _() {
    cin.sync_with_stdio(0);
    cin.tie(0);
  }
} _;
const int MOD = 1e9 + 7;
const long long INFLL = 1e18 + 7;
const int MAXN = -1;
int n, m;
int main() {
  cin >> n;
  vector<int> h(n);
  for (int(i) = (0); (i) < (n); ++(i)) {
    cin >> h[i];
  }
  long long f = h[0] - 1;
  long long g = f;
  if (n > 1 && h[1] < h[0]) g = h[1] - 1;
  ;
  ;
  for (int(i) = (1); (i) < (n); ++(i)) {
    int h_f = min(h[i - 1], h[i]);
    int h_g = h_f;
    if (i != n - 1) h_g = min(h_g, h[i + 1]);
    int d_g = ((h_g - 1) * 1LL * g) % MOD;
    int d_f = ((h_f - 1) * 1LL * g) % MOD;
    f = (h[i] - 1LL + d_f + f) % MOD;
    if (i != n - 1) g = (min(h[i], h[i + 1]) - 1LL + d_g) % MOD;
    ;
    ;
  }
  cout << f << endl;
  return 0;
}
