#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(2, 0));
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[i] = {tmp, i + 1};
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int x = 0; x < i + 1; x++) {
      int y = i - x;
      long long activity = a[i - 1][0];
      int ind = a[i - 1][1];
      int val1 = 0;
      int val2 = 0;
      if (y - 1 >= 0) {
        val1 = dp[x][y - 1] + activity * (abs(n - (y - 1) - ind));
      }
      if (x - 1 >= 0) {
        val2 = dp[x - 1][y] + activity * (abs(ind - x));
      }
      dp[x][y] = max(val1, val2);
      if (i == n && dp[x][y] > ans) {
        ans = dp[x][y];
      }
    }
  }
  cout << ans << endl;
}
