#include <bits/stdc++.h>
using namespace std;
template <typename T>
T nextInt() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') {
    p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * p;
}
const int maxN = (int)1e6 + 10;
const int INF = (int)1e9 + 5;
const int mod = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 5;
int h[maxN];
long long mul(long long a, long long b) { return (a * b) % mod; }
int len(int l, int r) { return max(0, r - l + 1); }
int main() {
  int n;
  n = nextInt<int>();
  for (int i = 1; i <= n; ++i) {
    h[i] = nextInt<int>();
  }
  h[0] = INF;
  h[n + 1] = INF;
  long long res = h[1] - 1;
  long long sum = len(h[1] >= h[2] ? h[1] - h[2] + 1 : 1, h[1] - 1);
  for (int i = 2; i <= n; ++i) {
    int l = max(1, h[i] - h[i - 1] + 1);
    int r = h[i] - 1;
    res += mul(sum, len(l, r)) + h[i] - 1;
    res %= mod;
    sum = mul(sum, len(max(l, h[i] - h[i + 1] + 1), r)) +
          len(h[i] >= h[i + 1] ? h[i] - h[i + 1] + 1 : 1, h[i] - 1);
    sum %= mod;
  }
  printf("%I64d\n", res);
  return 0;
}
