#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long res = 1ll * a[0] * (n - a[0] + 1);
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) continue;
    if (a[i] > a[i - 1]) {
      res += 1ll * (a[i] - a[i - 1]) * (n - a[i] + 1);
    } else {
      res += 1ll * a[i] * (a[i - 1] - a[i]);
    }
  }
  cout << res;
  return 0;
}
