#include <bits/stdc++.h>
using namespace std;
long long f(long long n) {
  if (n < 1) return 0;
  return (n * (n + 1)) / 2;
}
int main() {
  long long n, i, j, k, s = 0, x, y, z;
  cin >> n;
  long long a[n + 1];
  a[n] = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    if (a[i + 1] != a[i]) {
      if (a[i + 1] < a[i]) {
        x = n - a[i + 1];
        y = a[i] - a[i + 1] - 1;
        z = n - a[i];
      } else {
        x = a[i + 1];
        y = a[i];
        z = a[i + 1] - a[i];
      }
      s = s + (f(x) - (f(y) + f(z)));
    }
  }
  cout << s << "\n";
  return 0;
}
