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