#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int n;
int main() {
  scanf("%d", &n);
  int Hold, Hth, Hnew;
  long long FN;
  long long ans;
  ans = FN = Hold = Hnew = Hth = 0;
  scanf("%d", &Hth);
  Hth--;
  for (int i = 1; i < n; i++) {
    scanf("%d", &Hnew);
    Hnew--;
    ans += Hth + min(Hth, Hold) * FN;
    ans %= MOD;
    FN = min(Hth, Hnew) + min(min(Hth, Hnew), Hold) * FN;
    FN %= MOD;
    Hold = Hth;
    Hth = Hnew;
  }
  Hnew = 0;
  ans += Hth + min(Hth, Hold) * FN;
  ans %= MOD;
  printf("%lld\n", ans);
  return 0;
}
