#include <bits/stdc++.h>
const long long MOD = 1000000007;
int N, a[1000001];
long long O;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", a + i);
    O = (O + --a[i]) % MOD;
  }
  long long T = 0;
  for (int i = 2; i <= N; i++)
    O = (O + (T = (T * std::min(std::min(a[i - 2], a[i - 1]), a[i]) +
                   std::min(a[i - 1], a[i])) %
                  MOD) *
                 std::min(a[i - 1], a[i])) %
        MOD;
  printf("%lld\n", O);
}
