#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 5;
const long long inf = 0x3f3f3f3f;
const long long mod = 1000000007;
long long n;
long long h[maxn];
long long s[maxn];
int main() {
  while (scanf("%I64d", &n) == 1) {
    memset(h, 0, sizeof(h));
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", h + i);
      h[i]--;
    }
    long long res = 0;
    memset(s, 0, sizeof(s));
    for (int i = 1; i <= n; i++) {
      s[i + 1] =
          (s[i] * min(h[i - 1], min(h[i], h[i + 1])) + min(h[i], h[i + 1])) %
          mod;
      res = (res + s[i + 1] * min(h[i], h[i + 1])) % mod;
    }
    for (int i = 1; i <= n; i++) {
      res += h[i];
      res %= mod;
    }
    printf("%I64d\n", res);
  }
  return 0;
}
