#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 85 - 69;
const long long int Mod = 1e9 + 7;
long long int a[maxn];
long long int dp[maxn];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  a[n] = Mod;
  if (n == 1) {
    cout << a[0] << endl;
    return 0;
  }
  for (int i = n - 1; i > 0; i--) {
    dp[i] =
        min(a[i - 1], min(a[i], a[i + 1])) * dp[i + 1] + min(a[i], a[i - 1]);
    dp[i] %= Mod;
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++)
    ans = (ans + min(a[i], a[i + 1]) * dp[i + 1] + a[i]) % Mod;
  cout << ans << endl;
  return 0;
}
