#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1, n;
  while (t--) {
    cin >> n;
    pair<int, int> arr[10000];
    for (int i = 0; i < n; i++) {
      cin >> arr[i].first;
      arr[i].second = i;
    }
    sort(arr, arr + n);
    reverse(arr, arr + n);
    long long int ans = INT_MIN;
    vector<vector<long long int>> dp(n + 1, vector<long long int>(n + 1, 0));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; (i + j) <= n; j++) {
        if (i + j == n)
          ans = max(dp[i][j], ans);
        else {
          dp[i + 1][j] = (long long int)max(
              dp[i + 1][j], (long long int)dp[i][j] +
                                abs(i - arr[i + j].second) * arr[i + j].first);
          dp[i][j + 1] = (long long int)max(
              dp[i][j + 1],
              (long long int)dp[i][j] +
                  abs(n - j - 1 - arr[i + j].second) * arr[i + j].first);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
