#include <bits/stdc++.h>
using namespace std;
int f[100005];
long long ans;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> f[i];
  for (int i = 1; i < n; i++) {
    if (f[i] > f[i - 1])
      ans += 1ll * (f[i] - f[i - 1]) * f[i - 1];
    else if (f[i] < f[i - 1])
      ans += 1ll * (n - f[i - 1] + 1) * (f[i - 1] - f[i]);
  }
  ans += 1ll * (n - f[n - 1] + 1) * f[n - 1];
  cout << ans << endl;
  return 0;
}
