#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
long long int dp[3][maxn];
long long int ans;
int a[maxn];
int h[maxn];
int n;
inline void input();
inline void ok_dp();
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
}
inline void input() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  ok_dp();
}
inline void ok_dp() {
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      dp[0][i] = min(h[i], h[i + 1]) - 1;
      dp[1][i] = h[i] - 1;
    } else if (i == n) {
      dp[1][i] = (1ll * (min(h[i], h[i - 1]) - 1) * dp[2][i - 1]) % mod +
                 (1ll * (min(h[i], h[i - 1]) - 1) * dp[0][i - 1]) % mod + h[i] -
                 1;
    } else {
      dp[0][i] = min(h[i], h[i + 1]) - 1;
      dp[1][i] = (1ll * (min(h[i], h[i - 1]) - 1) * dp[2][i - 1]) % mod +
                 (1ll * (min(h[i], h[i - 1]) - 1) * dp[0][i - 1]) % mod + h[i] -
                 1;
      dp[2][i] =
          (1ll * (min(h[i], min(h[i - 1], h[i + 1])) - 1) * dp[2][i - 1]) %
              mod +
          (1ll * (min(h[i], min(h[i - 1], h[i + 1])) - 1) * dp[0][i - 1]) % mod;
    }
    dp[0][i] %= mod;
    dp[1][i] %= mod;
    dp[2][i] %= mod;
  }
  for (int i = 1; i <= n; i++) {
    ans += dp[1][i];
    ans %= mod;
  }
  cout << ans;
}
