#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int M = 100000 + 10;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t, n, m, k, p, l, r, u, v;
long long ans, cnt, flag, temp, sum;
long long a[N];
char str;
struct node {};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    if (a[i] > a[i - 1])
      ans += (a[i] - a[i - 1]) * (n - a[i] + 1);
    else if (a[i] != a[i - 1])
      ans += (a[i - 1] - a[i]) * a[i];
  }
  cout << ans << "\n";
  return 0;
}
