#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const mod = 1e9 + 7;
inline void safe_add(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline int safe_mul(int x, int y) { return x * 1LL * y % mod; }
struct Ohmygod {
  int lastOnes;
  int lastVal;
  int lastH;
  Ohmygod(int ones = 1, int val = 0, int h = 1)
      : lastOnes(ones), lastVal(val), lastH(h) {}
};
Ohmygod s;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int curH;
    cin >> curH;
    int curVal = 1;
    safe_add(curVal, safe_mul(s.lastVal, min(s.lastOnes - 1, curH - 1)));
    safe_add(curVal, min(s.lastH - s.lastOnes, max(0, curH - s.lastOnes)));
    int curOnes = min(curH, s.lastH);
    safe_add(ans, safe_mul(curVal, curOnes - 1));
    safe_add(ans, curH - curOnes);
    s = {curOnes, curVal, curH};
  }
  cout << ans << endl;
}
