#include <bits/stdc++.h>
using namespace std;
int a[1000010];
long long b[1000010];
int inf = 1e9 + 7;
int main() {
  int n, i, res = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  res = (accumulate(a + 1, a + n + 1, 0LL) - n) % inf;
  for (i = 2; i <= n; i++) {
    b[i] = (b[i - 1] * min({a[i - 2] - 1, a[i - 1] - 1, a[i] - 1}) +
            min(a[i - 1] - 1, a[i] - 1)) %
           inf;
    res = (res + min(a[i - 1] - 1, a[i] - 1) * b[i]) % inf;
  }
  printf("%d\n", res);
  return 0;
}
