#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100, inf = 2e9 + 1, mod = 1e9 + 7;
int n;
long long a[maxn], q[maxn], p[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  q[0] = 1;
  p[0] = a[0] - 1;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] >= a[i - 1])
      q[i] = p[i - 1], p[i] = (q[i] * (a[i - 1] - 1)) % mod;
    else {
      long long x = (i == 1 ? 1e9 : a[i - 2]), y = a[i - 1], z = a[i];
      if (x >= z)
        q[i] = ((z - 1) * q[i - 1]) % mod;
      else
        q[i] = ((x - 1) * q[i - 1] + z - x) % mod;
      p[i] = (q[i] * (a[i] - 1)) % mod;
    }
    p[i] += a[i] - 1;
    q[i]++;
  }
  for (int i = 0; i < n; i++) ans = (ans + p[i]) % mod;
  cout << ans;
}
