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