#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
const int MOD = 1e9 + 7;
int dp[N], h[N], n, sum;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", h + i);
    --h[i];
  }
  h[n + 1] = h[n];
  for (int i = 1; i <= n; ++i) {
    if (h[i] <= h[i + 1]) {
      dp[i] = (dp[i - 1] * 1LL * min(h[i - 1], h[i]) + h[i]) % MOD;
    } else {
      dp[i] = (dp[i - 1] * 1LL * min(h[i - 1], h[i + 1]) + h[i + 1]) % MOD;
      sum = (sum + max(min(h[i - 1], h[i]) - h[i + 1], 0) * 1LL * dp[i - 1]) %
            MOD;
      sum = (sum + h[i] - h[i + 1]) % MOD;
    }
    sum = (sum + dp[i]) % MOD;
  }
  cout << sum << endl;
  return 0;
}
