#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int n, a[N];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  ans = 1ll * a[1] * (n - a[1] + 1);
  for (int i = 2; i <= n; ++i) {
    int p = max(a[i], a[i - 1]), q = min(a[i], a[i - 1]);
    ans -= 1ll * (n - p + 1) * q;
    ans += 1ll * a[i] * (n - a[i] + 1);
  }
  printf("%lld", ans);
  return 0;
}
