#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int M = 1000005;
const int md = 1000000007;
long long n, i, r, ans, a[N], dp[N];
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> a[i];
  if (a[1] > 0) dp[1] = 1;
  r = a[1];
  ans = a[1] - 1;
  for (i = 2; i <= n; ++i) {
    if (a[i - 1] < a[i]) {
      dp[i] = (dp[i - 1] * (r - 1) + a[i - 1] - r) % md;
      r = a[i - 1];
      ans = (ans + (dp[i] * (r - 1)) % md + a[i] - 1) % md;
      ++dp[i];
      dp[i] %= md;
    } else {
      if (r >= a[i]) {
        dp[i] = (dp[i - 1] * (a[i] - 1)) % md;
        r = a[i];
        ans = (ans + (dp[i] * (r - 1)) % md + a[i] - 1) % md;
        ++dp[i];
        dp[i] %= md;
      } else {
        dp[i] = (dp[i - 1] * (r - 1) + a[i] - r) % md;
        r = a[i];
        ans = (ans + (dp[i] * (r - 1)) % md + a[i] - 1) % md;
        ++dp[i];
        dp[i] %= md;
      }
    }
  }
  cout << ans;
}
