#include <bits/stdc++.h>
using namespace std;
const int mod = 1e+9 + 7;
int mul_mod(int a, int b) {
  if (a > b) swap(a, b);
  if (a == 0) return 0;
  return ((a & 1) ? (mul_mod(a - 1, b) + b) % mod
                  : mul_mod(a >> 1, (b << 1) % mod));
}
int main() {
  int n, h[2] = {}, val = 0, not_ones = 0;
  long long int ans = 0;
  scanf("%d", &n);
  for (bool curr = 0; n--; curr = !curr) {
    scanf("%d", &h[curr]);
    int top = min(--h[curr], h[!curr]);
    val = (1 + mul_mod(val, min(not_ones, top)) + max(0, top - not_ones)) % mod;
    not_ones = top;
    ans = (ans + mul_mod(val, not_ones) + h[curr] - not_ones) % mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
