#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long n, dat[MAXN], ans;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) dat[i] = read();
  for (int i = 1; i <= n; i++)
    if (dat[i + 1] > dat[i])
      ans += (dat[i + 1] - dat[i]) * dat[i];
    else
      ans += (n - dat[i] + 1) * (dat[i] - dat[i + 1]);
  cout << ans << endl;
  return 0;
}
