#include <bits/stdc++.h>
using namespace std;
int a[1000010], n, mo = 1000000007;
long long dp[1000010], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    a[i]--;
  }
  dp[1] = min(a[1], a[2]);
  for (int i = 2; i <= n; i++) {
    dp[i] =
        (min(a[i], a[i + 1]) + min(a[i - 1], min(a[i], a[i + 1])) * dp[i - 1]) %
        mo;
    if (a[i + 1] >= a[i])
      ans = (ans + dp[i]) % mo;
    else
      ans = (ans + min(a[i], a[i - 1]) * dp[i - 1] + a[i]) % mo;
  }
  printf("%I64d\n", (ans + a[1]) % mo);
  return 0;
}
