#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  int last = 0;
  for (int i = 1; i <= n; ++i) {
    int tmp;
    cin >> tmp;
    ans += 1LL * tmp * (n - tmp + 1);
    int m = min(tmp, last), M = max(tmp, last);
    ans -= 1LL * m * (n - M + 1);
    last = tmp;
  }
  cout << ans << endl;
}
