#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 1000000;
const int MOD = 1000000007;
int n;
int x[MAXN];
int l[MAXN], m[MAXN], r[MAXN];
void inc(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &x[i]), --x[i];
  for (int i = (0); i < (n - 1); ++i) l[i] = min(x[i], x[i + 1]);
  l[n - 1] = x[n - 1];
  r[0] = x[0];
  for (int i = (1); i < (n); ++i) r[i] = min(x[i - 1], x[i]);
  for (int i = (0); i < (n); ++i) m[i] = min(l[i], r[i]);
  int ret = 0, sum = 0;
  for (int i = (0); i < (n); ++i) {
    inc(ret, x[i]);
    inc(ret, (long long)sum * r[i] % MOD);
    sum = (long long)sum * m[i] % MOD;
    inc(sum, l[i]);
  }
  printf("%d\n", ret);
}
int main() {
  run();
  return 0;
}
