#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(1e6) + 322;
const long long INF = (long long)(1e9);
const long long mod = (long long)(1e9) + 7;
const double eps = 1e-9;
long long n, a[N], res, dp[N], cur;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i]--;
    res += a[i];
  }
  res %= mod;
  cur = min(a[1], a[2]);
  for (long long i = 2; i <= n; ++i) {
    res += cur * min(a[i], a[i - 1]);
    cur *= min(a[i], min(a[i - 1], a[i + 1]));
    cur += min(a[i], a[i + 1]);
    res %= mod;
    cur %= mod;
  }
  cout << res;
  return 0;
}
