#include <bits/stdc++.h>
using namespace std;
long long h[1000005];
long long dp[1000005][2];
const int mod = 1e9 + 7;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &h[i]), h[i]--;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] * min(h[i], h[i - 1]) + h[i]) % mod;
    dp[i][1] = ((min(h[i + 1], h[i])) +
                min(h[i + 1], min(h[i], h[i - 1])) * dp[i - 1][1]) %
               mod;
  }
  printf("%I64d\n", dp[n][0]);
  return 0;
}
