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