#include <bits/stdc++.h>
struct infant {
  int position;
  int lively;
  bool operator<(const infant &right) const {
    return lively == right.lively ? position < right.position
                                  : lively < right.lively;
  }
};
int main() {
  int N = 0;
  std::cin >> N;
  std::vector<infant> vec_infants(N);
  for (int cnt = 0; cnt < N; cnt++) {
    vec_infants.at(cnt).position = cnt + 1;
    std::cin >> vec_infants.at(cnt).lively;
  }
  sort(vec_infants.begin(), vec_infants.end());
  reverse(vec_infants.begin(), vec_infants.end());
  std::vector<std::vector<int> > dp(N + 1, std::vector<int>(N + 1, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - i; j++) {
      int left_renge = std::abs((i + 1) - vec_infants.at(i + j).position);
      if (dp.at(i).at(j) <
          dp.at(i).at(j) + vec_infants.at(i + j).lively * left_renge) {
        dp.at(i + 1).at(j) =
            dp.at(i).at(j) + vec_infants.at(i + j).lively * left_renge;
      }
      int right_renge = std::abs((N - j) - vec_infants.at(i + j).position);
      if (dp.at(i).at(j) <
          dp.at(i).at(j) + vec_infants.at(i + j).lively * right_renge) {
        dp.at(i).at(j + 1) =
            dp.at(i).at(j) + vec_infants.at(i + j).lively * right_renge;
      }
    }
  }
  int answer = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      answer = std::max(dp.at(i).at(j), answer);
    }
  }
  std::cout << answer << std::endl;
  return 0;
}
