#include <bits/stdc++.h>
using namespace std;
const int P = (1000 * 1000 * 1000) + 7;
const int arrn = 2e5 + 3;
template <typename T>
T _rv(vector<T> &in) {
  T _readin;
  cin >> _readin;
  in.push_back(_readin);
  return _readin;
}
vector<long long> vals;
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    vals.push_back(v);
  }
  long long out = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      out += (vals[i] * (n - vals[i] + 1));
    else {
      int x = vals[i - 1] - 1;
      int y = vals[i - 1] + 1;
      if (vals[i] >= 1 && vals[i] <= x) {
        out += vals[i] * (x - vals[i] + 1);
      } else if (vals[i] >= y && vals[i] <= n) {
        out += (vals[i] - y + 1) * (n - vals[i] + 1);
      }
    }
  }
  cout << out;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
