#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const long long mod = 1e9 + 7;
long long ans, sum;
long long h[maxn];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &h[i]), h[i]--;
  ans = h[1];
  sum = min(h[1], h[2]);
  for (int i = 2; i <= n; i++) {
    long long temp = 0;
    temp += sum * min(h[i], h[i - 1]) % mod;
    temp = (temp + h[i]) % mod;
    ans = (ans + temp) % mod;
    long long now = 0;
    now += sum * min(h[i], min(h[i - 1], h[i + 1])) % mod;
    now = (now + min(h[i], h[i + 1])) % mod;
    sum = now;
  }
  printf("%lld\n", ans);
}
