#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, hgs = 1e9 + 7;
int n, a[N], f[N], g[N], ans;
int Min(int A, int B, int C) { return min(A, min(B, C)); }
signed main() {
  scanf("%d", &n);
  for (register int i = (1); i <= (n); ++i) scanf("%d", &a[i]), a[i]--;
  g[1] = ans = a[1];
  f[1] = min(a[1], a[2]);
  for (register int i = (2); i <= (n); ++i) {
    f[i] = 1ll * f[i - 1] * Min(a[i], a[i - 1], a[i + 1]) % hgs +
           min(a[i], a[i + 1]);
    f[i] %= hgs;
    g[i] = 1ll * f[i - 1] * min(a[i - 1], a[i]) % hgs + a[i];
    g[i] %= hgs;
    ans += g[i];
    ans %= hgs;
  }
  printf("%d\n", ans);
  return 0;
}
