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