#include <bits/stdc++.h>
using namespace std;
int amount;
int numbers[200005];
long long cal(int exist, int without) {
  if (exist < without)
    return (long long)exist * (without - exist);
  else
    return (long long)(amount - exist + 1) * (exist - without);
}
void solve() {
  long long res = 0;
  for (int i = 1; i <= amount; i++) res += cal(numbers[i], numbers[i - 1]);
  printf("%lld", res);
}
int main() {
  scanf("%d", &amount);
  for (int i = 1; i <= amount; i++) scanf("%d", &numbers[i]);
  solve();
}
