#include <bits/stdc++.h>
const long long llinfinity = 9223372036854775807LL;
const long long llminusinfinity = -9223372036854775808LL;
const int intinfinity = 2147483647;
const int intminusinfinity = -2147483648;
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], n;
long long ans;
int main(int argc, char *argv[]) {
  long long tmp = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  ans = 0;
  for (int i = 0; i < n; ++i) {
    tmp = 0;
    if (i == 0) {
      tmp = a[i];
      tmp *= (n - a[i] + 1);
    } else {
      if (a[i] > a[i - 1]) {
        tmp = a[i] - a[i - 1];
        tmp *= n - a[i] + 1;
      } else {
        tmp = a[i];
        tmp *= a[i - 1] - a[i];
      }
    }
    ans += tmp;
  }
  printf("%lld\n", ans);
  return 0;
}
