#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
  int n;
  while (scanf("%d", &n) > 0) {
    scanf("%d", &a[1]);
    long long ans = (long long)a[1] * (n - a[1] + 1);
    for (int i = 2; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i - 1] < a[i]) {
        ans += (long long)(a[i] - a[i - 1]) * (n - a[i] + 1);
      }
      if (a[i - 1] > a[i]) {
        ans += (long long)a[i] * (a[i - 1] - a[i]);
      }
    }
    printf("%lld\n", ans);
  }
}
