#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int n;
long long h[1000100];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &h[i]);
    h[i]--;
  }
  long long val = 1ll;
  long long H = h[n - 1], rem = 0;
  long long ans = h[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    if (h[i] > h[i + 1]) {
      val = (val * H + rem + 1) % 1000000007;
      H = h[i + 1];
      rem = h[i] - h[i + 1];
    } else {
      val = min(H, h[i]) * val + max(h[i] - H, 0ll) + 1;
      val %= 1000000007;
      H = h[i];
      rem = 0;
    }
    ans += (val * H + rem) % 1000000007;
    ans %= 1000000007;
  }
  printf("%I64d\n", ans);
  return 0;
}
