#include <bits/stdc++.h>
using namespace std;
long long a[100007];
int main() {
  long long n;
  long long ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i] * (n - a[i] + 1);
  }
  for (int i = 1; i < n; i++)
    ans -= (min(a[i], a[i + 1])) * (n + 1 - max(a[i], a[i + 1]));
  cout << ans << endl;
  return 0;
}
