#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
int a[maxn];
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > a[i - 1]) ans += (a[i] - a[i - 1]) * 1LL * (n - a[i] + 1);
    if (a[i] < a[i - 1]) ans += a[i] * 1LL * (a[i - 1] - a[i]);
  }
  cout << ans;
  return 0;
}
