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