#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[1000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 40;
const long long maxn = 1e6 + 100;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 100;
long long dp[maxn][2];
long long res;
long long h[maxn];
int32_t main() {
  long long n = in();
  for (long long i = 0; i < n; i++) h[i] = in();
  h[n] = h[n - 1];
  dp[0][0] = h[0] - 1;
  dp[0][1] = min(h[0], h[1]) - 1;
  for (long long i = 1; i < n; i++) {
    dp[i][0] = ((h[i] - 1) + dp[i - 1][1] * min(h[i] - 1, h[i - 1] - 1)) % mod;
    dp[i][1] = (min(h[i] - 1, h[i + 1] - 1) +
                dp[i - 1][1] * (min(h[i], min(h[i - 1], h[i + 1])) - 1)) %
               mod;
  }
  for (long long i = 0; i < n; i++) {
    res = (res + dp[i][0]) % mod;
  }
  cout << res << "\n";
}
