#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<vector<T>> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < (int)n; ++i) cin >> a[i];
  vector<long long> cnt(n, 0);
  for (int i = 0; i < (int)n; ++i) cnt[a[i] - 1]++;
  long long res = 0;
  for (int i = 0; i < (int)n; ++i) {
    res += (i + 1) * (n - i) * cnt[i];
  }
  for (int i = 0; i < (int)n - 1; ++i) {
    long long lb = min(a[i], a[i + 1]);
    long long ub = max(a[i], a[i + 1]);
    res -= lb * (n + 1 - ub);
  }
  cout << res << endl;
  return 0;
}
