#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
long long h[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0, pass = 0;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    h[i]--;
    ans += h[i];
    ans %= 1000000007;
  }
  h[0] = h[n + 1] = 2e9;
  for (int i = 1; i <= n; i++) {
    ans = (ans + (pass * min(h[i], h[i - 1]))) % 1000000007;
    pass = (pass * min(h[i], min(h[i - 1], h[i + 1]))) % 1000000007 +
           min(h[i], h[i + 1]);
    pass %= 1000000007;
  }
  cout << ans << '\n';
  return 0;
}
