#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[100010];
int main() {
  int n = read();
  for (int i = (1); i <= (n); ++i) a[i] = read();
  long long ans = 0;
  for (int i = (1); i <= (n); ++i) {
    if (a[i - 1] < a[i]) {
      ans += 1ll * (a[i] - a[i - 1]) * (n - a[i] + 1);
    } else {
      ans += 1ll * (a[i - 1] - a[i]) * a[i];
    }
  }
  printf("%lld\n", ans);
}
