#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
const int N = 1000010;
long long a[N], f[N][2], g[N], sum[N], ans;
int n;
void add(long long& ans, long long t) { ans = (ans + t) % mod; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  f[0][0] = 1;
  g[0] = 2;
  sum[0] = a[0] - 1;
  ans = 0;
  add(ans, sum[0]);
  for (int i = 1; i < n; i++) {
    if (a[i] > a[i - 1]) {
      g[i] = a[i - 1] + 1;
      f[i][0] = 1;
      add(f[i][1], sum[i - 1] + 1);
    } else {
      g[i] = 2;
      if (g[i - 1] <= a[i])
        add(f[i][0], (g[i - 1] - 2) * f[i - 1][1] +
                         (a[i] - g[i - 1] + 1) * f[i - 1][0] + 1);
      else
        add(f[i][0], (a[i] - 1) * f[i - 1][1] + 1);
    }
    add(sum[i], (g[i] - 2) * f[i][1] + (a[i] - g[i] + 1) * f[i][0]);
    add(ans, sum[i]);
  }
  printf("%I64d\n", ans);
  return 0;
}
