#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long ssum = 0, ff = 1;
  char ch;
  for (ch = getchar(); !isdigit(ch) && ch != '-'; ch = getchar())
    ;
  if (ch == '-') ff = -1, ch = getchar();
  for (; isdigit(ch); ch = getchar()) ssum = ssum * 10 + ch - '0';
  return ssum * ff;
}
const long long M = 1e5 + 5;
long long n, a[M], cnt[M], ans;
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) a[i] = getint(), cnt[a[i]]++;
  for (long long i = 1; i <= n; i++) ans += (cnt[i] * (n + 1 - i) * i);
  for (long long i = 1; i < n; i++) {
    long long l = a[i], r = a[i + 1];
    if (l > r) swap(l, r);
    ans -= (l * (n - r + 1));
  }
  cout << ans << endl;
  return 0;
}
