#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
int n, h[N];
int eval(vector<pair<int, int>> &f, int x) {
  int res = 0;
  f.emplace_back(INF, 0);
  for (int i = 0; x > f[i].first; i++) {
    res += (long long)min(f[i + 1].first - f[i].first, x - f[i].first) *
           f[i].second % MOD;
    if (res >= MOD) res -= MOD;
  }
  f.pop_back();
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", h + i);
  vector<pair<int, int>> act, nxt;
  act.emplace_back(0, 0);
  int lastHeight = INF, ans = 0;
  for (int i = 0; i < n; i++) {
    nxt.clear();
    if (h[i] <= lastHeight) {
      int K = eval(act, h[i]);
      nxt.emplace_back(1, (K + 1) % MOD);
      nxt.emplace_back(h[i], 0);
    } else {
      int K = eval(act, INF);
      nxt.emplace_back(1, (K + 1) % MOD);
      nxt.emplace_back(lastHeight, 1);
      nxt.emplace_back(h[i], 0);
    }
    swap(act, nxt);
    ans += eval(act, INF);
    if (ans >= MOD) ans -= MOD;
    lastHeight = h[i];
  }
  printf("%d\n", ans);
  return 0;
}
