#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1000000007;
int cnt[N];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    int first;
    scanf("%d", &first);
    if (arr.size() == 0 || first != arr.back()) {
      arr.push_back(first);
      cnt[first]++;
    }
  }
  long long int tot = 0;
  for (long long int i = 1; i <= n; i++) {
    tot += i * (n - i + 1) * cnt[i];
  }
  for (int i = 1; i < arr.size(); i++) {
    long long int l = min(arr[i], arr[i - 1]);
    long long int r = max(arr[i], arr[i - 1]);
    tot -= l * (n - r + 1);
  }
  cout << tot << endl;
}
