#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  int a[q], sum = 0, mx = 0;
  for (int i = 0; i < q; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < q - 1; j++) {
      mx = max(mx, a[i] * abs(a[j] - a[j + 1]));
    }
    sum += mx;
    mx = 0;
  }
  cout << sum << endl;
}
