#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int n;
long long h[maxn];
long long d[maxn][2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &h[i]), h[i]--;
  for (int i = 1; i <= n; i++) {
    d[i][0] = (d[i - 1][0] + d[i - 1][1] * min(h[i - 1], h[i]) + h[i]) % mod;
    d[i][1] = (min(min(h[i - 1], h[i]), h[i + 1]) * d[i - 1][1] +
               min(h[i], h[i + 1])) %
              mod;
  }
  printf("%I64d\n", d[n][0]);
  return 0;
}
