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