#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10, MOD = 1e9 + 7;
int h[N], dp[N], n, ans, dpl[N];
int sum(int a, int b) {
  int c = a + b;
  if (c >= MOD) c -= MOD;
  return c;
}
int mul(int a, int b) { return 1LL * a * b % MOD; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i], dp[i] = h[i] - 1;
  dpl[0] = 1;
  for (int i = 1; i < n; i++) {
    if (h[i] == 1) continue;
    if (h[i] >= h[i - 1]) {
      dpl[i] = dp[i - 1];
      dp[i] = sum(dp[i], mul(h[i - 1] - 1, dpl[i]));
    } else {
      if (i == 1) {
        dpl[i] = h[i] - 1;
        dp[i] = sum(dp[i], mul(dpl[i], h[i] - 1));
      } else if (h[i - 2] >= h[i - 1]) {
        dpl[i] = mul(dpl[i - 1] + 1, h[i] - 1);
        dp[i] = sum(dp[i], mul(dpl[i], h[i] - 1));
      } else {
        dpl[i] = h[i] - 1;
        dpl[i] = sum(dpl[i], mul(min(h[i - 2], h[i]) - 1, dp[i - 2]));
        dp[i] = sum(dp[i], mul(dpl[i], h[i] - 1));
      }
    }
  }
  for (int i = 0; i < n; i++) ans = sum(ans, dp[i]);
  cout << ans;
}
