#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int a[1000100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    a[i]--;
  }
  a[0] = a[n + 1] = 2e9;
  long long d = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + a[i] + d * min(a[i], a[i - 1])) % p;
    d = (d * min(a[i - 1], min(a[i], a[i + 1])) + min(a[i], a[i + 1])) % p;
  }
  cout << (ans % p + p) % p << endl;
  return 0;
}
