#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int mainsolve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (n); ++i) cin >> a[i];
  vector<pair<long long, long long>> ps(n);
  for (long long i = 0; i < (n); ++i)
    ps[i] = pair<long long, long long>(a[i], i);
  sort(ps.rbegin(), ps.rend());
  long long INF = 1e18;
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, -INF));
  for (long long i = 0; i < (n + 1); ++i) dp[0][i] = 0;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (n); ++j) {
      long long chooseL = 0, chooseR = 0;
      if (i >= j + 1)
        chooseR = dp[i][j + 1] + ps[i].first * (n - (i - j) - ps[i].second);
      if (i >= j) chooseL = dp[i][j] + ps[i].first * (ps[i].second - j);
      if (i + 1 >= j + 1) {
        dp[i + 1][j + 1] = max(chooseL, chooseR);
        assert(dp[i + 1][j + 1] >= 0);
      }
    }
  }
  long long res = 0;
  for (long long i = 0; i < (n + 1); ++i) res = max(res, dp[n][i]);
  cout << res << endl;
  return 0;
}
int main() { return mainsolve(); }
