#include <bits/stdc++.h>
using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) cin >> a[i].first, a[i].second = i;
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  vector<vector<int>> dp(n, vector<int>(n, 0));
  dp[0] = {a[0].first * abs(a[0].second - n + 1),
           a[0].first * abs(a[0].second)};
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 0; j <= i + 1; j++) {
      if (j == 0)
        dp[i][j] = dp[i - 1][j] + a[i].first * abs(a[i].second - n + 1 + i - j);
      else if (j <= i)
        dp[i][j] =
            max(dp[i - 1][j - 1] + a[i].first * abs(a[i].second - j + 1),
                dp[i - 1][j] + a[i].first * abs(a[i].second - n + 1 + i - j));
      else
        dp[i][j] = dp[i - 1][j - 1] + a[i].first * abs(a[i].second - j + 1);
    }
  }
  cout << *max_element(dp[n - 1].begin(), dp[n - 1].end());
  return 0;
}
