#include <bits/stdc++.h>
using namespace std;
int n;
long long ans, h[1000010], f[1000010][2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &h[i]), h[i]--;
  f[1][0] = h[1];
  f[1][1] = min(h[1], h[2]);
  for (int i = 2; i <= n; i++) {
    f[i][1] = (min(h[i - 1], min(h[i], h[i + 1])) * f[i - 1][1] +
               min(h[i], h[i + 1])) %
              1000000007;
    f[i][0] = (min(h[i - 1], h[i]) * f[i - 1][1] + h[i]) % 1000000007;
  }
  for (int i = 1; i <= n; i++) ans = (ans + f[i][0]) % 1000000007;
  printf("%lld\n", ans);
  return 0;
}
