#include <bits/stdc++.h>
using namespace std;
long long a[1000005], x[1000005], mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, i;
  cin >> n;
  for (i = 0; i < n; ++i) cin >> a[i], --a[i];
  a[n] = 1e15;
  x[0] = min(a[0], a[1]);
  long long y, z = a[0];
  for (i = 1; i < n; ++i) {
    y = (x[i - 1] * min(a[i - 1], a[i]) + a[i]) % mod;
    if (a[i] < a[i + 1])
      x[i] = y;
    else
      x[i] = (x[i - 1] * min(a[i - 1], a[i + 1]) + a[i + 1]) % mod;
    z = (z + y) % mod;
  }
  cout << z;
}
