#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265359;
const long long MOD = (long long)1e9 + 7;
const long long MAXN = (long long)2e5 + 6;
const long long INF = (long long)2242545357980376863;
const long double EPS = (long double)1e-8;
long long a[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += (a[i] * (n - a[i] + 1ll));
  for (int i = 1; i < n; i++) {
    long long mn = min(a[i], a[i - 1]);
    long long mx = a[i] + a[i - 1] - mn;
    ans -= (mn * (n - mx + 1));
  }
  cout << ans;
  return 0;
}
