#include <bits/stdc++.h>
using namespace std;
long long int solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  long long int cnt[100001] = {0};
  for (long long int j = 0; j < n; j++) {
    cin >> v[j];
    cnt[v[j]]++;
  }
  long long int s = 0;
  for (long long int j = 1; j <= n; j++) {
    s += cnt[j] * ((j) * (n - j + 1));
  }
  for (long long int j = 0; j < n - 1; j++) {
    s -= (min(v[j], v[j + 1])) * (n - max(v[j], v[j + 1]) + 1);
  }
  cout << s << "\n";
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
