#include <bits/stdc++.h>
using namespace std;
const int mn = 2006;
int a[mn], id[mn];
long long f[mn][mn], ans;
bool cmp(int x, int y) { return a[x] > a[y]; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= n - 1; ++i) {
    scanf("%d", a + i);
    id[i] = i;
  }
  sort(id, id + n, cmp);
  for (int i = 0; i <= n - 1; ++i)
    for (int j = 0; j <= n - i - 1; ++j) {
      int k = i + j;
      f[i + 1][j] = max(f[i + 1][j], f[i][j] + 1ll * a[id[k]] * abs(id[k] - i));
      f[i][j + 1] =
          max(f[i][j + 1], f[i][j] + 1ll * a[id[k]] * abs(id[k] - (n - j - 1)));
    }
  for (int i = 0; i <= n; ++i) ans = max(ans, f[i][n - i]);
  cout << ans;
}
