#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
const int MAXN = 100005;
int n, A[MAXN];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  ans = (long long)A[0] * (n - A[0] + 1);
  for (int i = 0; i < n - 1; i++) {
    if (A[i] < A[i + 1]) {
      ans += (long long)(A[i + 1] - A[i]) * (n - A[i + 1] + 1);
    } else if (A[i] > A[i + 1]) {
      ans += (long long)A[i + 1] * (A[i] - A[i + 1]);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
