#include <bits/stdc++.h>
using namespace std;
int n;
bool vis[2005];
long long ans;
struct rr {
  long long pos, w;
} a[2005];
long long b[2005];
bool cmp(rr u, rr v) { return u.w > v.w; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    a[i].w = b[i];
    a[i].pos = i;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (a[i].pos > n / 2) {
      for (int j = 1; j <= n; j++) {
        if (vis[j] == 0) {
          vis[j] = 1;
          ans += a[i].w * abs(j - a[i].pos);
          break;
        }
      }
    } else {
      for (int j = n; j > 0; j--) {
        if (vis[j] == 0) {
          vis[j] = 1;
          ans += a[i].w * abs(j - a[i].pos);
          break;
        }
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  long long ans1 = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].pos >= n / 2) {
      for (int j = 1; j <= n; j++) {
        if (vis[j] == 0) {
          vis[j] = 1;
          ans1 += a[i].w * abs(j - a[i].pos);
          break;
        }
      }
    } else {
      for (int j = n; j > 0; j--) {
        if (vis[j] == 0) {
          vis[j] = 1;
          ans1 += a[i].w * abs(j - a[i].pos);
          break;
        }
      }
    }
  }
  cout << max(ans, ans1);
  return 0;
}
