#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
long long dp[2005][2005];
void solve() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > z(n);
  int i, j;
  for (i = 0; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    z[i] = make_pair(tmp, i);
  }
  sort(z.rbegin(), z.rend());
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n; j++) {
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j <= i; j++) {
      if (dp[i][j] < 0) continue;
      int val = z[i].first;
      int id = z[i].second;
      dp[i + 1][j + 1] =
          ((dp[i + 1][j + 1]) < (dp[i][j] + (long long)val * (id - j))
               ? (dp[i][j] + (long long)val * (id - j))
               : (dp[i + 1][j + 1]));
      dp[i + 1][j] =
          ((dp[i + 1][j]) < (dp[i][j] + (long long)val * (n - 1 - (i - j) - id))
               ? (dp[i][j] + (long long)val * (n - 1 - (i - j) - id))
               : (dp[i + 1][j]));
    }
  }
  long long ans = 0;
  for (j = 0; j <= n; j++) {
    ans = ((ans) < (dp[n][j]) ? (dp[n][j]) : (ans));
  }
  printf("%lld\n", ans);
  return;
}
int main(int argc, char* argv[]) {
  solve();
  return 0;
}
