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