#include <bits/stdc++.h>
using namespace std;
long long DP[2000][2000];
int main(void) {
  int N, a;
  vector<int> As;
  vector<pair<int, int>> As_pair;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    As.push_back(a);
    As_pair.push_back(make_pair(a, i));
  }
  sort(As_pair.begin(), As_pair.end(), greater<pair<int, int>>());
  int m, x, y;
  for (m = 1; m <= N; ++m) {
    for (x = 0; x <= m; ++x) {
      y = m - x;
      if (x == 0) {
        DP[0][m] = DP[0][m - 1] +
                   As_pair[m - 1].first * abs(As_pair[m - 1].second - (N - m));
      } else if (y == 0) {
        DP[m][0] = DP[m - 1][0] +
                   As_pair[m - 1].first * abs(As_pair[m - 1].second - (m - 1));
      } else {
        DP[x][y] = max(DP[x - 1][y] + As_pair[m - 1].first *
                                          abs(As_pair[m - 1].second - (x - 1)),
                       DP[x][y - 1] + As_pair[m - 1].first *
                                          abs(As_pair[m - 1].second - (N - y)));
      }
    }
  }
  long long ans(0);
  for (x = 0; x <= N; ++x) {
    ans = max(ans, DP[x][N - x]);
  }
  cout << ans << endl;
  return 0;
}
