#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vl = vector<ll>;
template <typename T>
void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}
template <typename T>
void pv(vector<T> vec) {
  cout << "[";
  for (auto& v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}
template <>
void pv(vector<P> vec) {
  cout << "[";
  for (auto& v : vec) {
    cout << "<" << v.first << "," << v.second << ">"
         << ",";
  }
  cout << "]" << endl;
}
ll dp[2005][2005];
int main() {
  int n;
  cin >> n;
  vp a(n);
  for (int i = 0; i < (n); ++i) {
    int t;
    cin >> t;
    a.at(i) = P(t, i);
  }
  sort((a).rbegin(), (a).rend());
  for (int j = 0; j < (n); ++j)
    dp[0][j + 1] = dp[0][j] + a.at(j).first * abs(n - a.at(j).second - j - 1);
  for (int i = 0; i < (n); ++i)
    dp[i + 1][0] = dp[i][0] + a.at(i).first * abs(a.at(i).second - i);
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j) {
      if (i + j > n - 1) continue;
      if (i == 0) continue;
      ll u = a.at(i + j).first;
      ll d = a.at(i + j).second;
      dp[i][j + 1] = max(dp[i][j] + u * abs(n - d - j - 1),
                         dp[i - 1][j + 1] + u * abs(d - i + 1));
    }
  ll res = 0;
  for (int i = 0; i < (n + 1); ++i) {
    res = max(res, dp[i][n - i]);
  }
  cout << res << endl;
  return 0;
}
