#include <bits/stdc++.h>
using namespace std;
long long base = 1e9 + 7;
long long h[1000005], y[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long long sum = 0, sum2 = 1, sum3;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    sum += h[i] - 1;
  }
  if (n == 1) {
    cout << sum;
    return 0;
  }
  for (int r = 2; r <= n; r++) {
    sum2 = sum2 * min(h[r - 1] - 1, h[r] - 1) % base;
  }
  long long tmp = min(h[1] - 1, h[2] - 1);
  sum3 = tmp * min(h[1] - 1, h[2] - 1);
  for (int r = 3; r <= n; r++) {
    tmp = (tmp * min(h[r - 2] - 1, min(h[r - 1] - 1, h[r] - 1)) +
           min(h[r - 1] - 1, h[r] - 1)) %
          base;
    sum3 = (sum3 + tmp * min(h[r - 1] - 1, h[r] - 1)) % base;
  }
  cout << (sum + sum3) % base;
}
