#include <bits/stdc++.h>
using namespace std;
int rd() {
  int ans = 0, sign = 1;
  char c = getchar();
  while (!(('0' <= (c) && (c) <= '9') || (c) == '-')) c = getchar();
  if (c == '-') sign = -1, c = getchar();
  while ((('0' <= (c) && (c) <= '9') || (c) == '-'))
    ans = (ans << 3) + (ans << 1) + c - '0', c = getchar();
  return sign == 1 ? ans : -ans;
}
const int N = 2005;
int n, a[N];
int p[N];
int main() {
  n = rd();
  for (register int i = 1, kkllkl = n; i <= kkllkl; ++i) {
    a[i] = rd();
    p[i] = i;
  }
  int ans = 0;
  for (register int i = 1, kkllkl = n; i <= kkllkl; ++i)
    for (register int j = 1, kkllkl = n - 1; j <= kkllkl; ++j) {
      int old =
          ((p[j] - j) > 0 ? (p[j] - j) : -(p[j] - j)) * a[p[j]] +
          ((p[j + 1] - j - 1) > 0 ? (p[j + 1] - j - 1) : -(p[j + 1] - j - 1)) *
              a[p[j + 1]];
      swap(p[j], p[j + 1]);
      int New =
          ((p[j] - j) > 0 ? (p[j] - j) : -(p[j] - j)) * a[p[j]] +
          ((p[j + 1] - j - 1) > 0 ? (p[j + 1] - j - 1) : -(p[j + 1] - j - 1)) *
              a[p[j + 1]];
      if (old > New)
        swap(p[j], p[j + 1]);
      else
        ans += New - old;
    }
  printf("%d\n", ans);
  return 0;
}
