#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> arr(n + 1, -1);
  long long int ans = (n * (n + 1)) / 2;
  cin >> arr[1];
  for (int i = 2; i <= n; i++) {
    cin >> arr[i];
    if (i != n)
      ans = ans + (arr[i] * (arr[i] - 1)) / 2 +
            ((n - arr[i]) * (n - arr[i] + 1)) / 2;
    long long int mini = min(arr[i], arr[i - 1]);
    long long int maxi = max(arr[i], arr[i - 1]);
    long long int temp = ((n - maxi) * (n - maxi + 1)) / 2 +
                         ((mini) * (mini - 1)) / 2 +
                         ((maxi - mini - 1) * (maxi - mini)) / 2;
    ans -= temp;
  }
  cout << ans << endl;
  return 0;
}
