#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int ha = 1e9 + 7;
long long A[N], n, m, l, r, ans = 0;
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  for (int i = 1; i <= n + 1; ++i)
    if (A[i - 1] < A[i])
      ans += (A[i] - A[i - 1]) * (n - A[i] + 1);
    else
      ans -= (A[i] - A[i - 1]) * A[i];
  cout << ans << endl;
}
