#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[2001][2001], ans = 0;
vector<pair<int, int>> a;
int main() {
  cin >> n;
  for (int i = 0, m; i < n; i++) {
    cin >> m;
    a.emplace_back(m, i);
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i + 1; j++) {
      dp[i + 1][j + 1] =
          max(dp[i + 1][j + 1], dp[i][j] + abs(j - a[i].second) * a[i].first);
      dp[i + 1][j] =
          max(dp[i + 1][j],
              dp[i][j] + abs(n - i + j - 1 - a[i].second) * a[i].first);
    }
  }
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << endl;
}
