#include <bits/stdc++.h>
using namespace std;
long long f[1000010];
long long g[1000010];
long long mod = 1e9 + 7;
long long h[1000010];
long long ans = 0;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    h[i]--;
  }
  for (int i = 1; i <= n; i++) {
    long long x = (f[i - 1] - g[i - 1] + mod) % mod;
    long long m1 = min(h[i], h[i - 1]);
    long long m2 = max(0ll, m1 - h[i + 1]);
    f[i] = ((1ll * x * m1) % mod + h[i]) % mod;
    g[i] = max(0ll, ((1ll * x * m2) % mod + max(0ll, (h[i] - h[i + 1])))) % mod;
    ans += f[i];
    ans %= mod;
  }
  cout << (ans + mod) % mod;
}
