#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 1000000007;
const long long INF = 1e12;
const long long N = 2005;
pair<long long, long long> A[N];
long long dp[N][N];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) cin >> A[i].first, A[i].second = i;
  sort(A + 1, A + n + 1);
  reverse(A + 1, A + n + 1);
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < i + 1; j++) {
      if ((i - j) > 0)
        dp[i - j][j] = max(dp[i - j][j],
                           abs((n - (i - j) + 1) - A[i].second) * A[i].first +
                               dp[i - j - 1][j]);
      if (j > 0)
        dp[i - j][j] = max(
            dp[i - j][j], abs(j - A[i].second) * A[i].first + dp[i - j][j - 1]);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n + 1; i++) ans = max(ans, dp[i][n - 1 - i]);
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long no;
  no = 1;
  while (no--) {
    solve();
  }
  return 0;
}
