#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7, mod = 1e9 + 7;
long long a[N], dp[N], n;
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    --a[i];
  }
  long long ans = 0;
  for (long long i = n; i >= 1; i--) {
    long long k = min(a[i - 1], a[i]);
    dp[i] = k + min(k, a[i + 1]) * dp[i + 1] % mod;
    dp[i] %= mod;
  }
  for (long long i = 1; i <= n; i++) {
    ans += a[i];
    ans %= mod;
    ans += min(a[i], a[i + 1]) * dp[i + 1] % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
