#include <bits/stdc++.h>
using namespace std;
int const mod = 1e9 + 7;
int h[1000000];
int hs[1000000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  for (int i = 0; i < n; i++) {
    if (i > 0 && i < n - 1) hs[i] = min(min(h[i - 1], h[i]), h[i + 1]) - 1;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) ans = (ans + h[i] - 1) % mod;
  long long s = 0;
  long long sn;
  for (int r = 1; r < n; r++) {
    sn = ((s * hs[r - 1]) % mod + min(h[r], h[r - 1]) - 1) % mod;
    ans = (ans + (sn * min(h[r] - 1, h[r - 1] - 1)) % mod) % mod;
    s = sn;
  }
  printf("%I64d", ans);
  return 0;
}
