#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10;
int n, a[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (a[i] > a[i + 1])
      ans += 1LL * (a[i] - a[i + 1]) * (n - a[i] + 1);
    else if (a[i] < a[i + 1])
      ans += 1LL * (a[i + 1] - a[i]) * (a[i]);
  cout << ans << '\n';
  return 0;
}
