#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N];
int num[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    num[a[i]]++;
  }
  long long tot_num = 0;
  for (int i = 1; i <= n; ++i) {
    tot_num += 1ll * num[i] * i * (n - i + 1);
  }
  long long tot_edge = 0;
  for (int i = 1; i + 1 <= n; ++i) {
    int lt = a[i], rt = a[i + 1];
    if (lt > rt) swap(lt, rt);
    tot_edge += 1ll * lt * (n - rt + 1);
  }
  cout << tot_num - tot_edge << endl;
}
