#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exp, long long MOD) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return (res % MOD);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long *a = new long long[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  ans += a[0] * (n - a[0] + 1);
  for (long long i = 1; i < n; i++) {
    if (a[i - 1] < a[i])
      ans += (a[i] - a[i - 1]) * (n - a[i] + 1);
    else if (a[i - 1] > a[i])
      ans += a[i] * (a[i - 1] - a[i]);
  }
  cout << ans;
  delete[] a;
  return 0;
}
