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