#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MOD2 = 998244353;
vector<pair<long long, long long> > vp;
long long dp[1010][1010];
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    vp.push_back({a, i});
  }
  sort(vp.begin(), vp.end());
  reverse(vp.begin(), vp.end());
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j + i <= n; j++) {
      long long cl = vp[i + j].first * (vp[i + j].second - i);
      long long cr = vp[i + j].first * (n - j - 1 - vp[i + j].second);
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + cl);
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + cr);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, dp[i][n - i]);
  cout << ans << endl;
  return 0;
}
