#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 1000006;
int H[N];
int main() {
  int n;
  scanf("%d", &n);
  bool allSame = true;
  long long int prev;
  long long int ans = 0;
  long long int prevH = 0;
  long long int cur;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &H[i]);
    H[i]--;
    if (H[i] <= H[i - 1]) {
      if (allSame) {
        cur = (H[i] * prev + 1) % mod;
        ans += cur * H[i];
        ans %= mod;
        prev = cur;
      } else {
        cur = min(prevH, H[i] * 1LL) * prev + max(H[i] - prevH, 0LL) + 1;
        cur %= mod;
        ans += cur * H[i];
        ans %= mod;
        prev = cur;
      }
      allSame = true;
    } else {
      if (allSame) {
        prevH = H[i - 1];
        ans += H[i] - H[i - 1];
        cur = (H[i - 1] * prev + 1) % mod;
        ans += cur * H[i - 1];
        ans %= mod;
        prev = cur;
      } else {
        ans += H[i] - H[i - 1];
        cur = prevH * prev + (H[i - 1] - prevH) + 1;
        cur %= mod;
        prevH = H[i - 1];
        ans += cur * H[i - 1];
        ans %= mod;
        prev = cur;
      }
      allSame = false;
    }
  }
  cout << ans << "\n";
  return 0;
}
