#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t N;
  cin >> N;
  vector<int> A(N);
  for (int &a : A) {
    cin >> a;
  }
  priority_queue<pair<int, size_t>> q;
  for (size_t i = 0; i < N; i++) {
    q.push(make_pair(A[i], i));
  }
  vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
  for (size_t i = 0; !q.empty(); i++) {
    for (size_t j = 0; j <= i; j++) {
      dp[j + 1][i - j] =
          max(dp[j + 1][i - j],
              dp[j][i - j] + q.top().first * int(q.top().second - j));
      dp[j][i - j + 1] = max(
          dp[j][i - j + 1],
          dp[j][i - j] + q.top().first * int(N - 1 - (i - j) - q.top().second));
    }
    q.pop();
  }
  int ans = 0;
  for (size_t i = 0; i <= N; i++) {
    ans = max(ans, dp[i][N - i]);
  }
  cout << ans << endl;
}
