#include <bits/stdc++.h>
using namespace std;
long long n;
long long times(long long val) {
  long long under = (val * (val - 1)) / 2;
  long long over = ((n - val) * (n - val + 1)) / 2;
  long long all = n * (n + 1) / 2;
  return all - (under + over);
}
long long right(long long a, long long b) {
  if (b < a) {
    return b * (a - b);
  } else if (b > a) {
    return (b - a) * (n + 1 - b);
  } else {
    return 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<long long> vals(n);
  for (long long i = 0; i < n; i++) {
    cin >> vals[i];
  }
  long long ans = times(vals[0]);
  for (long long i = 1; i < n; i++) {
    ans += right(vals[i - 1], vals[i]);
  }
  cout << ans << endl;
  return 0;
}
