#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10;
long long ans;
long long ar[MAXn], n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = n - 2; i >= 0; i--) {
    if (ar[i] < ar[i + 1]) {
      ans += (ar[i + 1] - ar[i]) * (ar[i]);
    } else if (ar[i] > ar[i + 1]) {
      ans += (ar[i] - ar[i + 1]) * (n - ar[i] + 1);
    }
  }
  ans += (ar[n - 1]) * (n - ar[n - 1] + 1);
  cout << ans;
}
