#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
long long dp[maxn][maxn];
int n;
struct person {
  int x, a;
} e[maxn];
bool cmp(person g, person h) { return g.a > h.a; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> e[i].a;
    e[i].x = i;
  }
  sort(e + 1, e + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] + e[i].a * abs(e[i].x - (n - i + 1));
    for (int j = 1; j < i; j++) {
      dp[i][j] = max(dp[i - 1][j - 1] + e[i].a * abs(e[i].x - j),
                     dp[i - 1][j] + e[i].a * abs(e[i].x - (n - i + j + 1)));
    }
    dp[i][i] = dp[i - 1][i - 1] + e[i].a * abs(e[i].x - i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}
