#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < (n); ++i) {
    int ae;
    cin >> ae;
    a.emplace_back(ae, i);
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >());
  vector<vector<int> > dp(n + 1, vector<int>(n + 1));
  for (int xy = 1; xy <= (n); ++xy) {
    for (int x = 0; x < (xy + 1); ++x) {
      int y = xy - x;
      int left = abs(a.at(xy - 1).second - x + 1) * a.at(xy - 1).first;
      int right = abs(n - y - a.at(xy - 1).second) * a.at(xy - 1).first;
      if (0 < x && x != xy) {
        dp.at(xy).at(x) =
            max(dp.at(xy - 1).at(x - 1) + left, dp.at(xy - 1).at(x) + right);
      } else if (x == 0) {
        dp.at(xy).at(x) = dp.at(xy - 1).at(x) + right;
      }
      if (x == xy) {
        dp.at(xy).at(x) = dp.at(xy - 1).at(x - 1) + left;
      }
    }
  }
  int ans;
  for (int x = 0; x < (n + 1); ++x) {
    ans = max(ans, dp.at(n).at(x));
  }
  cout << ans << endl;
  return 0;
}
