#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int _N = (int)1e6 + 5;
long long n, h[_N], dp[_N], res = 0;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &h[i]);
    res += --h[i];
  }
  res %= MOD;
  for (int i = 2; i <= n; i++) {
    dp[i] = (min(min(h[i - 1], h[i - 2]), h[i]) * dp[i - 1]) % MOD;
    dp[i] = (dp[i] + min(h[i - 1], h[i]));
    res = (res + (min(h[i - 1], h[i]) * dp[i]) % MOD) % MOD;
  }
  printf("%lld\n", res);
  return 0;
}
