#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int rd() {
  char c = getchar();
  int s = 0, f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
  return s * f;
}
int n, a[N];
long long ans;
int main() {
  n = rd();
  for (int i = 1; i <= n; i++) a[i] = rd();
  for (int i = 1; i <= n; i++) {
    if (a[i + 1] > a[i])
      ans += 1ll * (a[i + 1] - a[i]) * a[i];
    else
      ans += 1ll * (a[i] - a[i + 1]) * (n - a[i] + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
