#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 1000100;
long long a[maxn];
int main() {
  {
    srand(time(0));
    const string file = "";
    if (!file.empty()) {
      freopen((file + ".in").c_str(), "r", stdin);
      freopen((file + ".out").c_str(), "w", stdout);
    }
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  long long ans = 0, pref = 0;
  for (int i = 0; i < n; i++) {
    ans += pref * (min(a[i], i ? a[i - 1] : mod) - 1) + a[i] - 1;
    ans %= mod;
    long long h = min(i ? a[i - 1] : mod, i + 1 == n ? mod : a[i + 1]);
    h = min(h, a[i]);
    h--;
    pref *= h;
    pref += min(a[i], i + 1 < n ? a[i + 1] : mod) - 1;
    pref %= mod;
  }
  printf("%lld", ans);
  return (0);
}
