#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
void Main() {
  int n;
  cin >> n;
  vector<pli> d;
  for (int(i) = 0; (i) < (n); (i)++) {
    int a;
    cin >> a;
    d.push_back(pli(a, i));
  }
  stable_sort((d.rbegin()), (d.rend()));
  vvi dp(n + 1, vi(n + 1, 0));
  dp[0][0] = 0;
  int temp, temp2;
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) <= (i + 1); (j)++) {
      temp = 0;
      temp2 = 0;
      if (i >= j) {
        temp = dp[i][j] + d[i].first * abs(n - d[i].second - 1 - (i - j));
      }
      if (j - 1 >= 0) {
        temp2 = dp[i][j - 1] + d[i].first * abs(d[i].second - (j - 1));
      }
      dp[i + 1][j] = max(temp, temp2);
    }
  }
  int ans = 0;
  for (int(j) = 0; (j) <= (n); (j)++) ans = max(ans, dp[n][j]);
  cout << ans << endl;
  return;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
