#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int N, h[1000005];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &h[i]);
  h[0] = h[N + 1] = 1;
  long long ans = 0, upto = 0, tmp;
  for (int p = 1; p <= N; p++) {
    ans += (h[p] - 1);
    ans += (min(h[p], h[p - 1]) - 1) * upto;
    ans %= mod;
    upto = (min(h[p], h[p + 1]) - 1) +
           (min(h[p - 1], min(h[p], h[p + 1])) - 1) * upto;
    upto %= mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
