#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 5;
const long long linf = 0x3f3f3f3f3f3f3f3f;
inline int Abs(int x) { return x < 0 ? -x : x; }
long long a[MAXN];
bool del[MAXN];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  int l = 1, r = n;
  long long ans = 0;
  for (int k = 1; k <= n; ++k) {
    int mxi = -1;
    long long mxVal = -linf;
    for (int i = 1; i <= n; ++i) {
      if (del[i]) continue;
      long long now = max(Abs(i - l) * a[i], Abs(i - r) * a[i]);
      if (now > mxVal) mxVal = now, mxi = i;
    }
    ans += mxVal;
    del[mxi] = 1;
    if (Abs(mxi - l) * a[mxi] > Abs(mxi - r) * a[mxi])
      ++l;
    else
      --r;
  }
  printf("%lld", ans);
  return 0;
}
