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