#include <bits/stdc++.h>
using namespace std;
const long long M = (long long)1e9 + 7;
vector<long long> h, dp, hlink;
long long n;
void init() {
  h.resize(n + 1);
  dp.resize(n + 1);
  hlink.resize(n + 1);
}
void solve() {
  dp[1] = h[1] > 1;
  hlink[1] = h[1];
  for (long long i = 2; i <= n; i++) {
    hlink[i] = min(h[i], h[i - 1]);
  }
  for (long long i = 2; i <= n; i++) {
    long long tmp = (min(h[i], hlink[i - 1]) - 1 + M) % M * dp[i - 1] % M +
                    max(0ll, h[i] - hlink[i - 1]) + (hlink[i] > 1);
    tmp %= M;
    (tmp += M) %= M;
    long long tmp2 = (hlink[i - 1] - 1 + M) % M * dp[i - 1] % M + h[i - 1] -
                     hlink[i - 1] + (hlink[i] > 1);
    tmp2 %= M;
    (tmp2 += M) %= M;
    if (h[i] <= h[i - 1]) {
      dp[i] = tmp;
    }
    if (h[i] > h[i - 1]) {
      dp[i] = tmp2;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += dp[i] * (hlink[i] - 1 + M) % M + h[i] - hlink[i];
    (ans += M) %= M;
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  init();
  for (long long i = 1; i <= n; i++) cin >> h[i];
  solve();
  return 0;
}
