#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, D = (1 << 18);
int n, a;
long long val[N];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
  }
  for (int i = 1; i <= n; i++)
    if (val[i - 1] > val[i]) {
      ans += val[i] * (val[i - 1] - val[i]);
    } else
      ans += (val[i] - val[i - 1]) * (n - val[i] + 1);
  printf("%lld", ans);
  return 0;
}
