#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
long long dp[2002][2002];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  pair<long long, long long> arr[n];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i].first;
    arr[i].second = i;
  }
  sort(arr + 1, arr + n + 1);
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= n + 1 - i; j++) {
      dp[j - 1][i + j - 1] = max(
          dp[j - 1][i + j - 1],
          dp[j - 1][i + j] + abs(arr[i].second - (i + j - 1)) * arr[i].first);
      dp[j][i + j] =
          max(dp[j][i + j],
              dp[j - 1][i + j] + abs(arr[i].second - j) * arr[i].first);
      ans = max(ans, dp[j][i + j]);
    }
  }
  cout << ans;
  return 0;
}
