#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long modPow(long long a, int b) {
  long long d = 1;
  for (int i = 30; i >= 0; i--) {
    d = (d * d) % MOD;
    if (b & (1 << i)) {
      d = (d * a) % MOD;
    }
  }
  return d;
}
long long getInv(long long a) { return modPow(a, MOD - 2); }
int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < (int)(n); i++) scanf("%d", &h[i]);
  long long ans = h[n - 1] - 1;
  long long sum = 0;
  vector<int> a(n);
  a[n - 1] = h[n - 1] - 1;
  for (int i = n - 2; i >= 0; i--) {
    a[i] = min(h[i], h[i + 1]) - 1;
    if (a[i] < a[i + 1]) {
      sum = (sum * getInv(a[i + 1])) % MOD;
      sum = (sum * a[i]) % MOD;
    }
    sum = (sum * a[i]) % MOD;
    sum += a[i] * 1ll * a[i];
    sum %= MOD;
    ans = (ans + sum + h[i] - 1) % MOD;
  }
  cout << ans << endl;
  return 0;
}
