#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long a[n + 2];
  a[0] = 0;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > a[i - 1])
      sum += (a[i] - a[i - 1]) * (n - a[i] + 1);
    else if (a[i] < a[i - 1])
      sum += a[i] * (a[i - 1] - a[i]);
  }
  cout << sum << endl;
}
