#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int eps = 1e-10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 100005;
int n;
long long a[maxn];
long long sum;
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i);
  a[0] = 0;
  sum = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > a[i - 1]) {
      sum += (n - a[i] + 1) * (a[i] - a[i - 1]);
    } else if (a[i] < a[i - 1]) {
      sum += (a[i - 1] - a[i]) * a[i];
    }
  }
  printf("%lld\n", sum);
  return 0;
}
