#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int mul(int x, int y) { return (long long)x * y % mod; }
int n;
int a[N], L[N], R[N], v[N], suf[N];
int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    ans = add(ans, a[i] - 1);
  }
  for (int i = 1; i < n; i++) R[i] = min(a[i] - 1, a[i + 1] - 1);
  for (int i = 2; i <= n; i++) L[i] = min(a[i - 1] - 1, a[i] - 1);
  for (int i = 2; i < n; i++) v[i] = min(L[i], R[i]);
  for (int i = n; i >= 1; i--) suf[i] = add(L[i], mul(v[i], suf[i + 1]));
  for (int i = 1; i < n; i++) ans = add(ans, mul(R[i], suf[i + 1]));
  printf("%d\n", ans);
  return 0;
}
