#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long sign = 1, sum = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') sign = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    sum = (sum << 1) + (sum << 3) + c - '0';
    c = getchar();
  }
  return sign * sum;
}
long long n, ans;
int main() {
  n = read();
  long long x = read();
  for (int i = 2; i <= n; ++i) {
    long long y = read();
    if (x > y)
      ans += (x - y) * (n - x + 1);
    else
      ans += (y - x) * x;
    x = y;
  }
  ans += x * (n - x + 1);
  printf("%lld\n", ans);
}
