#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX / 2;
signed main() {
  signed N;
  scanf("%d", &N);
  long long ans = 0, a = 0, b = 0, t = 0, h = 0;
  for (long long i__count = (0), i = i__count, i__goal = (N); i < i__goal;
       i = ++i__count) {
    signed H;
    scanf("%d", &H);
    --H;
    if (H > h) {
      b = a * (h - t) + b * t + 1;
      a = 1;
      t = h;
    } else {
      if (t > H) {
        b = b * H + 1;
      } else {
        b = a * (H - t) + b * t + 1;
      }
      a = 0;
      t = H;
    }
    h = H;
    a %= 1000000007;
    b %= 1000000007;
    ans += a * (h - t) + b * t;
    ans %= 1000000007;
    if (0) printf("%I64d %I64d %I64d %I64d\n", a, b, t, ans);
  }
  printf("%d\n", (signed)ans);
  return 0;
}
