#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000000;
const int MAXM = 200000;
const int INF = 1000000010;
const long long int MOD = 1000000007;
const double EPS = 1e-6;
int N;
long long int H[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%I64d", &H[i]);
    H[i]--;
  }
  long long int ans = H[0];
  long long int sum = 0, ones = H[0];
  for (int i = 1; i < N; i++) {
    if (H[i] > H[i - 1]) {
      sum = (sum * (H[i - 1] - ones) + ones + 1) % MOD;
      ones = (H[i] - H[i - 1]);
    } else {
      if (H[i - 1] - H[i] >= ones) {
        sum = (sum * H[i] + 1) % MOD;
      } else {
        sum = (sum * (H[i - 1] - ones) + (H[i] - H[i - 1] + ones) + 1) % MOD;
      }
      ones = 0;
    }
    ans = (ans + sum * (H[i] - ones) + ones) % MOD;
  }
  printf("%I64d", ans);
  return 0;
}
