#include <bits/stdc++.h>
using namespace std;
long long const mod = 1e9 + 7;
long long h[1100000], n;
long long ans, sum;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]--;
  for (int i = 1; i <= n; i++) {
    ans = (ans + min(h[i], h[i - 1]) * sum % mod + h[i]) % mod;
    sum =
        (min(h[i], h[i + 1]) + min(h[i], min(h[i - 1], h[i + 1])) * sum % mod) %
        mod;
  }
  cout << ans << endl;
  return 0;
}
