#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Read(T &x) {
  int f = 1;
  char t = getchar();
  while (t < '0' || t > '9') {
    if (t == '-') f = -1;
    t = getchar();
  }
  x = 0;
  while (t >= '0' && t <= '9') {
    x = x * 10 + t - '0';
    t = getchar();
  }
  x *= f;
}
template <class T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
template <class T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
const int modulo = 1000000007;
const int maxn = 1000005;
int n;
int h[maxn];
int f[maxn][2];
int coi[maxn];
void input() {
  Read(n);
  for (int i = 1; i <= n; i++) Read(h[i]), h[i]--;
}
void solve() {
  int ans = 0;
  for (int i = 1; i <= n; i++) coi[i] = min(h[i], h[i + 1]);
  for (int i = 1; i <= n; i++) {
    int l1 = h[i] - coi[i];
    int l2 = h[i] - l1;
    int s1 = min(l1, max(0, h[i - 1] - l2));
    int s2 = min(l2, h[i - 1]);
    f[i][0] = (l1 + 1ll * s1 * f[i - 1][1] % modulo) % modulo;
    f[i][1] = (l2 + 1ll * s2 * f[i - 1][1] % modulo) % modulo;
    ans = (ans + (f[i][0] + f[i][1]) % modulo) % modulo;
  }
  cout << ans << endl;
}
int main() {
  input();
  solve();
  return 0;
}
