#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> A(n);
  vector<pair<int, int> > Asort(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    Asort[i] = make_pair(-A[i], i);
  }
  sort(Asort.begin(), Asort.end());
  vector<vector<int> > DP(n + 1, vector<int>(n + 1, 0));
  DP[1][0] = -Asort[0].first * abs(Asort[0].second);
  DP[0][1] = -Asort[0].first * abs(Asort[0].second - n + 1);
  for (int i = 1; i < n; i++) {
    for (int L = 0, R = i + 1; L < n + 1 && R >= 0; L++, R--) {
      if (L > 0 && R > 0)
        DP[L][R] =
            max(DP[L - 1][R] - Asort[i].first * abs(L - 1 - Asort[i].second),
                DP[L][R - 1] - Asort[i].first * abs(n - R - Asort[i].second));
      else if (L == 0)
        DP[L][R] = DP[L][R - 1] - Asort[i].first * abs(n - R - Asort[i].second);
      else if (R == 0)
        DP[L][R] = DP[L - 1][R] - Asort[i].first * abs(L - 1 - Asort[i].second);
    }
  }
  int res = 0;
  for (int i = 0; i < n + 1; i++) {
    res = max(res, DP[i][n - i]);
  }
  cout << res << endl;
  return 0;
}
