#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
struct Pos {
  int pos;
  long long happiness;
};
bool cmp(const Pos &a, const Pos &b) { return a.happiness > b.happiness; }
const int MAX = 2001;
long long dp[MAX][MAX];
int main() {
  int n;
  cin >> n;
  vector<Pos> v(n);
  for (int i = 0; i < n; i++) {
    v[i].pos = i;
    cin >> v[i].happiness;
  }
  sort((v).begin(), (v).end(), cmp);
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int h = 0; h <= i; h++) {
      long long t = i - h;
      long long happy;
      happy = v[i].happiness * abs(v[i].pos - h);
      dp[h + 1][t] = max(dp[h + 1][t], dp[h][t] + happy);
      happy = v[i].happiness * abs(v[i].pos - (n - 1 - t));
      dp[h][t + 1] = max(dp[h][t + 1], dp[h][t] + happy);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
  return 0;
}
