#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n;
vector<int> a;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  a = vector<int>(n);
  for (int& x : a) cin >> x;
  long long ret = 0, left = 1;
  for (int i = 0; i < n; ++i) {
    if (i > 0) {
      int pp = i - 2 < 0 ? 0 : min(a[i - 1], a[i - 2]) - 1;
      int p = min(a[i - 1], a[i]) - 1;
      left = left * min(pp, p) + p;
      left %= mod;
      ret += left * p;
    }
    ret += a[i] - 1;
    ret %= mod;
  }
  cout << ret << endl;
}
