#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 1;
int main() {
  int n, a[MAX];
  long long res = 0;
  cin >> n;
  a[n + 1] = n + 1;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (a[i] != a[i + 1]) {
      long long x, y, z;
      x = min(a[i], a[i + 1]);
      y = max(a[i], a[i + 1]) - x;
      z = n + 1 - max(a[i], a[i + 1]);
      if (a[i] < a[i + 1])
        res = res + x * y;
      else
        res = res + y * z;
    }
  cout << res;
}
