#include <bits/stdc++.h>
using namespace std;
long long base = (long long)1e9 + 7;
long n;
long long h[1000010], f[1000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> h[i];
  h[0] = h[n + 1] = base;
  long long ans = h[1] - 1;
  for (int j = 2; j <= n; j++) {
    f[j] = f[j - 1] * (min(min(h[j - 2], h[j - 1]), h[j]) - 1) +
           min(h[j], h[j - 1]) - 1;
    f[j] %= base;
    ans += (long long)f[j] * min(h[j] - 1, h[j - 1] - 1) + h[j] - 1;
    ans %= base;
  }
  cout << ans;
  return 0;
}
