#include <bits/stdc++.h>
using namespace std;
long long ans, var;
long long a[1000200];
int x, i, n;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &x), a[i] = x;
  var = min(a[1], a[2]) - 1;
  ans += a[1] - 1;
  for (i = 2; i <= n; i++) {
    ans += (var * (min(a[i], a[i - 1]) - 1)) % 1000000007 + a[i] - 1;
    ans %= 1000000007;
    var = (var * (min(min(a[i], a[i - 1]), a[i + 1]) - 1)) % 1000000007 +
          min(a[i], a[i + 1]) - 1;
    var %= 1000000007;
  }
  cout << ans << endl;
}
