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