#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long long MAX_N = 200100;
long long dp[2020][2020];
signed main() {
  long long N;
  cin >> N;
  vector<pair<long long, long long>> q;
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    q.emplace_back(make_pair(tmp, i));
  }
  sort((q).begin(), (q).end());
  reverse((q).begin(), (q).end());
  queue<pair<long long, long long>> que;
  que.push(make_pair(0, 0));
  long long ans = 0;
  while (!que.empty()) {
    long long l = que.front().first;
    long long r = que.front().second;
    que.pop();
    long long idx = l + r;
    if (idx < N) {
      dp[l + 1][r] =
          max(dp[l + 1][r], dp[l][r] + q[idx].first * abs(q[idx].second - l));
      dp[l][r + 1] =
          max(dp[l][r + 1],
              dp[l][r] + q[idx].first * abs(q[idx].second - (N - 1 - r)));
      ans = max(ans, dp[l + 1][r]);
      ans = max(ans, dp[l][r + 1]);
      que.push(make_pair(l + 1, r));
      que.push(make_pair(l, r + 1));
    }
  }
  cout << ans << endl;
  return 0;
}
