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