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