#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = (0); i < (n); ++i) {
    int h;
    cin >> h;
    a[i] = make_pair(h, i + 1);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
  int hap = 0;
  for (int i = (0); i < (n + 1); ++i) {
    for (int j = (0); j < (n + 1); ++j) {
      if (i == 0 && j == 0) continue;
      if (i + j > n) break;
      if (j > 0) {
        dp[i][j] = dp[i][j - 1] +
                   a[i + j - 1].first * (n + 1 - j - a[i + j - 1].second);
      }
      if (i > 0) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + a[i + j - 1].first *
                                                    (a[i + j - 1].second - i));
      }
      hap = max(hap, dp[i][j]);
    }
  }
  cout << hap << '\n';
  return 0;
}
