#include <bits/stdc++.h>
using namespace std;
long long n, a[100007], ans;
signed main() {
  cin >> n;
  for (register long long i = 1; i <= n; i++) cin >> a[i];
  for (register long long i = 1; i <= n; i++) {
    ans += a[i] * (n - a[i] + 1);
    if (i != n) ans -= min(a[i], a[i + 1]) * (n - max(a[i], a[i + 1]) + 1);
  }
  cout << ans;
}
