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