#include <bits/stdc++.h>
using namespace std;
long long f[1000010], g[1000010], a[1000010];
const long long mod = 1000000007;
long long ans;
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i), a[i]--;
  for (int i = 1; i <= n; i++) {
    f[i] = min(a[i], a[i + 1]) % mod +
           min(a[i], min(a[i + 1], a[i - 1])) * f[i - 1] % mod;
    f[i] %= mod;
    g[i] = a[i] % mod + min(a[i], a[i - 1]) * f[i - 1] % mod;
    g[i] %= mod;
    ans += g[i];
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}
