#include <bits/stdc++.h>
using namespace std;
long long int n, k, m, t, a, b, l, r, temp1, temp2, x, y, temp, q, d,
    mod = 1e9 + 7, w, p, c;
vector<long long int> v(100008), val(100005);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  v[0] = 0;
  v[n + 1] = 1e18;
  long long int ans = 0;
  ans += (v[1] * (n - v[1] + 1));
  for (int i = 2; i <= n; i++) {
    if (v[i - 1] > v[i]) {
      ans += (v[i] * (v[i - 1] - v[i]));
    } else {
      ans += ((n - v[i] + 1) * (v[i] - v[i - 1]));
    }
  }
  cout << ans << endl;
}
