#include <bits/stdc++.h>
using namespace std;
long long h[1234567], m = 1e9 + 7, n, p, r;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", h + i), h[i]--;
  for (int i = 1; i <= n; i++) {
    r = (r + min(h[i], h[i - 1]) * p % m + h[i]) % m;
    p = (min(h[i], h[i + 1]) + min(h[i], min(h[i - 1], h[i + 1])) * p % m) % m;
  }
  cout << r;
}
