#include <bits/stdc++.h>
using namespace std;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
int n, m, k;
int a[M];
long long cal(long long x) {
  if (x < 1) return 0;
  return x * (x + 1) / 2;
}
long long cal(long long u, long long v) {
  return cal(u - 1) + cal(n - v) + cal(v - u - 1);
}
int main() {
  cin >> n;
  long long ans = 1ll * (n + 1) * n / 2;
  long long all = ans;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i];
    if (i != 1 && i != n) ans += cal(a[i], a[i]);
    if (i > 1) {
      ans -= cal(min(a[i], a[i - 1]), max(a[i], a[i - 1]));
    }
  }
  cout << ans << endl;
  return 0;
  int mi = a[1], mx = a[1];
  for (int i = (1); i <= (n); ++i) {
    mi = min(a[i], mi);
    mx = max(a[i], mx);
    ans -= cal(mi, mx);
  }
  mi = mx = a[n];
  for (int i = (n); i >= (2); --i) {
    mi = min(a[i], mi);
    mx = max(a[i], mx);
    ans -= cal(mi, mx);
  }
  cout << ans << endl;
  return 0;
}
