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