#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n + 2);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }
  long long res = 0, cont = 0;
  v[0] = v[n + 1] = 1000000000;
  for (int i = 1; i <= n; ++i) {
    int left = min(v[i - 1], v[i]);
    res += cont * (left - 1);
    res += v[i] - 1;
    cont *= min(left, v[i + 1]) - 1;
    cont += min(v[i], v[i + 1]) - 1;
    res %= MOD;
    cont %= MOD;
  }
  cout << res << endl;
}
