#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int n, a[N];
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= a[i - 1]) {
      ans += 1ll * (a[i] - a[i - 1]) * (n - a[i] + 1);
    } else {
      ans += 1ll * (a[i]) * (a[i - 1] - a[i]);
    }
  }
  for (int i = 1; i <= n / 2; i++) {
    swap(a[i], a[n + 1 - i]);
  }
  printf("%lld\n", ans);
  return 0;
}
