#include <bits/stdc++.h>
using namespace std;
int i, j, mini = 1000000000, p, d, n, m, k, ok, a, b, ul, c, op, maxi;
int v[1000050];
long long int rasp, first;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v[i];
    v[i]--;
  }
  v[0] = v[1];
  v[n + 1] = v[n];
  for (i = 1; i <= n; i++) {
    rasp = (rasp + v[i] + first * min(v[i - 1], v[i])) % 1000000007;
    first = (first * min(v[i - 1], min(v[i], v[i + 1])) + min(v[i], v[i + 1])) %
            1000000007;
  }
  cout << rasp;
  return 0;
}
