#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 100010;
int N;
int A[MAXN];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += ll(A[i]) * (N + 1 - A[i]);
  }
  for (int i = 0; i < N - 1; i++) {
    ans -= ll(min(A[i], A[i + 1])) * (N + 1 - max(A[i], A[i + 1]));
  }
  cout << ans << endl;
  return 0;
}
