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