#include <bits/stdc++.h>
const int mod = 1000000007;
int n, num[1000001];
int sum = 0;
long long ans = 0;
int read() {
  int x = 0, k = 1;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * k;
}
int min(int a, int b) { return a < b ? a : b; }
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) num[i] = read() - 1;
  ans = num[1];
  sum = min(num[1], num[2]);
  for (int i = 2; i <= n; ++i) {
    ans += ((sum * 1LL * min(num[i - 1], num[i]) * 1LL) % mod + num[i]);
    ans %= mod;
    sum = (1LL * sum * min(num[i + 1], min(num[i], num[i - 1])) * 1LL +
           min(num[i], num[i + 1]) * 1LL) %
          mod;
  }
  printf("%d\n", ans);
  return 0;
}
