#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long INF = 1e9;
inline long long pwr(long long base, long long n, long long m) {
  long long ans = 1;
  while (n > 0) {
    if (n % 2 == 1) ans = (ans * base) % m;
    base = (base * base) % m;
    n /= 2;
  }
  return ans;
}
const int N = 1e6 + 10;
long long h[N], dp[N][2];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  long long ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (i == 1 || h[i] <= h[i - 1])
      dp[i][0] = ((dp[i - 1][1] + 1) * (h[i] - 1)) % M;
    else {
      dp[i][0] = ((dp[i - 1][1] + 1) * (h[i - 1] - 1)) % M;
      dp[i][0] = (dp[i][0] + h[i] - h[i - 1]) % M;
    }
    if (i < n) {
      if (h[i + 1] < h[i]) {
        if (i == 1 || h[i] <= h[i - 1])
          dp[i][1] = ((dp[i - 1][1] + 1) * (h[i + 1] - 1)) % M;
        else {
          if (h[i - 1] >= h[i + 1])
            dp[i][1] = ((dp[i - 1][1] + 1) * (h[i + 1] - 1)) % M;
          else {
            dp[i][1] = ((dp[i - 1][1] + 1) * (h[i - 1] - 1)) % M;
            dp[i][1] = (dp[i][1] + h[i + 1] - h[i - 1]) % M;
          }
        }
      } else
        dp[i][1] = dp[i][0];
    }
    ans = (ans + dp[i][0]) % M;
  }
  cout << ans;
  return 0;
}
