#include <bits/stdc++.h>
using namespace std;
long long n, h[1000010], f[1000010], res;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (long long i = (1), _b = (n); i <= _b; i++) {
    cin >> h[i];
    h[i]--;
  }
  for (long long i = (1), _b = (n); i <= _b; i++)
    res = (res + h[i]) % 1000000007LL;
  for (long long i = (1), _b = (n); i <= _b; i++) {
    if (i > 1)
      res = (res + (f[i - 1] * min(h[i], h[i - 1])) % 1000000007LL) %
            1000000007LL;
    if (i < n) {
      f[i] = min(h[i], h[i + 1]);
      if (i > 1)
        f[i] = (f[i] + (min(min(h[i - 1], h[i + 1]), h[i]) * f[i - 1]) %
                           1000000007LL) %
               1000000007LL;
    }
  }
  cout << res;
  return 0;
}
