#include <bits/stdc++.h>
using namespace std;
long long const mod = 1e9 + 7;
int n;
long long h[1000005];
long long f[1000005], cur;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> h[i], h[i]--;
  long long cur;
  for (int i = 1; i <= n; i++) {
    long long tmp = min(h[i], h[i - 1]);
    f[i] = (f[i - 1] - cur) * tmp + h[i];
    f[i] %= mod;
    if (f[i] < 0) f[i] += mod;
    cur = ((f[i - 1] - cur) * max(0LL, (tmp - h[i + 1])) +
           max(0LL, (h[i] - h[i + 1]))) %
          mod;
    if (cur < 0) cur += mod;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + f[i]) % mod;
  cout << ans << endl;
  return 0;
}
