#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e7 + 5;
long long a[MAX], dp[MAX];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0),
      cout.precision(15);
  int n;
  while (cin >> n) {
    for (int i = int(1); i < int(n + 1); i++) cin >> a[i];
    for (int i = int(1); i < int(n + 1); i++) {
      dp[i] = dp[i - 1];
      dp[i] += a[i] * (n - a[i] + 1);
      if (i == 1) continue;
      long long m = min(a[i], a[i - 1]);
      long long M = max(a[i], a[i - 1]);
      dp[i] -= m * (n - M + 1);
    }
    cout << dp[n];
  }
  return 0;
}
