#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
const long long mod = 1e9 + 7;
int n, m;
long long ans;
long long a[mx];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] > a[i - 1]) {
      ans += (a[i] - a[i - 1]) * (n - a[i] + 1);
    } else {
      ans += a[i] * (a[i - 1] - a[i]);
    }
  }
  printf("%I64d\n", ans);
}
