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