#include <bits/stdc++.h>
using namespace std;
int a[1000005];
long long dp[2];
int main() {
  int n;
  while (cin >> n) {
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      a[i]--;
    }
    a[0] = a[1];
    a[n + 1] = a[n];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      int f = i & 1;
      int mn1 = min(a[i], a[i - 1]);
      int mn2 = min(a[i], a[i + 1]);
      ans = (ans + mn1 * 1LL * dp[1 - f] % 1000000007) % 1000000007;
      ans = (ans + a[i] * 1LL) % 1000000007;
      dp[f] = min(mn1, mn2) * 1LL * dp[1 - f] % 1000000007;
      dp[f] = (dp[f] + mn2 * 1LL) % 1000000007;
    }
    cout << ans << endl;
  }
  return 0;
}
