#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (i == 0)
      ans = a[i] * (n + 1 - a[i]);
    else {
      if (a[i] >= a[i - 1]) {
        ans += (a[i] - a[i - 1]) * (n + 1 - a[i]);
      } else {
        ans += (a[i - 1] - a[i]) * (a[i]);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
