#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1000 * 1000 + 24, delta = 1e9 + 7;
long long n;
long long h[MAX_N], dp[MAX_N], dpa[MAX_N];
long long q = 0;
int main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    h[i]--;
  }
  for (int i = 1; i <= n; i++) {
    dpa[i] = h[i];
    if (h[i - 1] <= h[i]) {
      dpa[i] += dpa[i - 1] * h[i - 1];
    } else {
      dpa[i] += dp[i - 1] * h[i];
    }
    dpa[i] %= delta;
    if (h[i] > h[i + 1]) {
      dp[i] = h[i + 1] + (dp[i - 1] * min(h[i + 1], h[i - 1]));
    } else {
      dp[i] = dpa[i];
    }
    dp[i] %= delta, dpa[i] %= delta;
    q += dpa[i], q %= delta;
  }
  cout << q << endl;
}
