#include <bits/stdc++.h>
using namespace std;
int n, a[2009], dp[2009][2009], id[2009];
bool cmp(int b1, int b2) { return a[b1] > a[b2]; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] + a[id[i]] * (id[i] - 1);
    for (int j = 1; j < i; j++) {
      dp[i][j] = max(dp[i - 1][j] + a[id[i]] * abs(n - (i - 1 - j) - id[i]),
                     dp[i - 1][j - 1] + a[id[i]] * abs(id[i] - j));
    }
    dp[i][i] = dp[i - 1][i - 1] + a[id[i]] * abs(id[i] - i);
  }
  cout << *max_element(dp[n], dp[n] + n + 1);
  return 0;
}
