#include <bits/stdc++.h>
using namespace std;
int N;
long long dp[2002][2002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  vector<pair<long long int, int>> v(N);
  for (int i = 0; i < N; i++) cin >> v[i].first, v[i].second = i + 1;
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < N; i++) {
    int len = N - i + 1;
    for (int j = 0; j + len < N + 2; j++) {
      dp[j + 1][j + len] =
          max(dp[j + 1][j + len],
              dp[j][j + len] + v[i].first * abs(v[i].second - (j + 1)));
      dp[j][j + len - 1] =
          max(dp[j][j + len - 1],
              dp[j][j + len] + v[i].first * abs(v[i].second - (j + len - 1)));
      cout << dp[j][j + len - 1] << endl;
    }
  }
  long long ans = 0;
  for (int i = 0; i < N + 1; i++) ans = max(ans, dp[i][i + 1]);
  cout << ans << endl;
  return 0;
}
