#include <bits/stdc++.h>
using namespace std;
void read(int& a) {
  a = 0;
  char k = getchar();
  int f = 1;
  for (; !isdigit(k); k = getchar())
    if (k == '-') f = -1;
  for (; isdigit(k); k = getchar()) a = a * 10 + k - '0';
  a *= f;
}
const int N = 2000 + 5;
int a[N], id[N], b[N], n, flag;
int abs(int x) { return x < 0 ? -x : x; }
int main() {
  read(n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) read(a[i]), b[i] = a[i], id[i] = i;
  flag = true;
  for (int i = 1; flag; ++i) {
    flag = false;
    for (int j = 1; j < n; ++j) {
      long long now =
          1LL * b[j] * abs(j - id[j]) + 1LL * b[j + 1] * abs(j + 1 - id[j + 1]);
      long long nw =
          1LL * b[j] * abs(j + 1 - id[j]) + 1LL * b[j + 1] * abs(j - id[j + 1]);
      if (nw > now) {
        flag = true;
        ans += nw - now;
        swap(id[j], id[j + 1]);
        swap(b[j], b[j + 1]);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
