#include <bits/stdc++.h>
using namespace std;
int n;
int A[100005];
long long f(int a, int b) {
  long long ret = 0;
  if (a > b) {
    ret += (long long)(n - a + 1) * (long long)(a - b) * 2ll;
    ret += (long long)(n - a + 1) * (long long)b;
  } else {
    ret += (long long)a * (long long)(b - a) * 2ll;
    ret += (long long)a * (long long)(n - b + 1);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> A[i];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int a = A[i];
    int b = A[i - 1];
    int c = A[i + 1];
    if (a <= b && a <= c) {
      ans += 2ll * (long long)(a) * (long long)(min(b, c) - a);
      ans += (long long)a * (long long)(abs(b - c));
    } else if (a >= b && a >= c) {
      ans += 2ll * (long long)(n - a + 1) * (long long)(a - max(b, c));
      ans += (long long)(n - a + 1) * (long long)(abs(b - c));
    } else {
      ans += (long long)(abs(b - a)) * (long long)(abs(a - c)) * 2ll;
      if (b > c) swap(b, c);
      ans += (long long)abs(c - a) * (long long)b;
      ans += (long long)abs(a - b) * (long long)(n - c + 1);
    }
  }
  cout << ans / 2ll;
  return 0;
}
