#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const long long N = 1000010, mod = 1000000007;
long long n, a[N], g[N], ans;
signed main() {
  n = read();
  for (long long i = 1; i <= n; ++i) a[i] = read() - 1;
  for (long long i = 1; i <= n; ++i) ans = (ans + a[i]) % mod;
  for (long long i = 2; i <= n; ++i)
    g[i] = (g[i - 1] * min(min(a[i - 2], a[i - 1]), a[i]) % mod +
            min(a[i - 1], a[i])) %
           mod;
  for (long long i = 1; i < n; ++i)
    ans = (ans + min(a[i], a[i + 1]) * g[i + 1] % mod) % mod;
  return printf("%lld\n", ans) & 0;
}
