#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<pair<int64_t, int64_t>> infant;
  for (int i = 0; i < (int)(N); i++) {
    int64_t A;
    cin >> A;
    infant.push_back(make_pair(A, i));
  }
  sort(infant.begin(), infant.end());
  reverse(infant.begin(), infant.end());
  for (int i = 0; i < (int)(N); i++) {
    cout << infant[i].first << infant[i].second << endl;
  }
  vector<vector<int64_t>> dp(2010, vector<int64_t>(2010, 0));
  int64_t ans = 0;
  for (int l = 0; l < (int)(N); l++) {
    for (int r = 0; r < (int)(N); r++) {
      if (l + r == N) {
        break;
      }
      dp[l + 1][r] =
          max(dp[l + 1][r],
              dp[l][r] + (abs(infant[l + r].second - l)) * infant[l + r].first);
      dp[l][r + 1] = max(dp[l][r + 1],
                         dp[l][r] + (abs(infant[l + r].second - (N - r - 1))) *
                                        infant[l + r].first);
    }
  }
  for (int l = 0; l < (int)(N + 1); l++) {
    ans = max(ans, dp[l][N - l]);
  }
  cout << ans << endl;
}
