#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
const int mod = 1e9 + 7;
int h[N + 10];
vector<pair<int, int> > v[N + 10];
vector<int> cnt[N + 10];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", h + i);
  }
  v[1].resize(1);
  cnt[1].resize(1);
  v[1][0] = make_pair(1, h[1] - 1);
  cnt[1][0] = 1;
  for (int i = 2; i <= n; i++) {
    if (h[i] > h[i - 1]) {
      v[i].resize(2);
      cnt[i].resize(2);
      v[i][1] = make_pair(h[i - 1], h[i] - 1);
      cnt[i][1] = 1;
      v[i][0] = make_pair(1, h[i - 1] - 1);
    } else {
      v[i].resize(1);
      cnt[i].resize(1);
      v[i][0] = make_pair(1, h[i] - 1);
    }
    if (v[i - 1][0].second < v[i][0].second) {
      int d = v[i - 1][0].second - v[i - 1][0].first + 1;
      int t = (1ll * d * cnt[i - 1][0]) % mod;
      t = (t + v[i][0].second - v[i - 1][0].second) % mod;
      cnt[i][0] = (t + 1) % mod;
    } else {
      int d = v[i][0].second - v[i][0].first + 1;
      int t = (1ll * d * cnt[i - 1][0]) % mod;
      cnt[i][0] = (t + 1) % mod;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int sz = v[i].size();
    for (int j = 0; j < sz; j++) {
      int d = v[i][j].second - v[i][j].first + 1;
      int t = (1ll * d * cnt[i][j]) % mod;
      ans = (ans + t) % mod;
    }
  }
  printf("%d\n", ans);
}
