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