#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  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());
  reverse(a.begin(), a.end());
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= i + 1; ++j) {
      dp[j][i + 1 - j] = max(
          dp[j][i + 1 - j],
          dp[j - 1][i + 1 - j] + 1ll * a[i].first * abs(a[i].second + 1 - j));
      dp[i + 1 - j][j] = max(
          dp[i + 1 - j][j],
          dp[i + 1 - j][j - 1] + 1ll * a[i].first * abs(a[i].second - (n - j)));
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; ++i) ans = max(ans, dp[i][n - i]);
  cout << ans;
  return 0;
}
