#include <bits/stdc++.h>
const int MAX_N = 1e5;
unsigned long long n;
unsigned long long a[MAX_N + 3];
void input() {
  std::cin >> n;
  for (int i = 1; i <= n; i++) std::cin >> a[i];
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(NULL);
  input();
  unsigned long long res = 0;
  for (int i = 1; i <= n - 1; i++) {
    unsigned long long x = a[i];
    unsigned long long y = a[i + 1];
    if (x == y) continue;
    if (y > x) {
      res += x * (y - x);
    } else {
      res += (n - x + 1) * (x - y);
    }
  }
  unsigned long long all = n * (n + 1) / 2;
  res += all;
  res -= (all) - (a[n] * (n - a[n] + 1));
  std::cout << res << "\n";
}
