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