#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct vec2 {
  int idx, val;
};
class Solution {
 private:
 public:
  long long solve(vector<vec2>& arr, int n) {
    sort(arr.begin(), arr.end(), [](const vec2& v1, const vec2& v2) -> bool {
      return v1.val > v2.val;
    });
    long long dp[n + 1][n + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j + i < n; ++j) {
        dp[i + 1][j] = max(dp[i + 1][j],
                           dp[i][j] + arr[i + j].val * abs(arr[i + j].idx - i));
        dp[i][j + 1] =
            max(dp[i][j + 1],
                dp[i][j] + arr[i + j].val * abs(n - 1 - j - arr[i + j].idx));
      }
    }
    long long ret = 0;
    for (int i = 0; i <= n; ++i) ret = max(ret, dp[i][n - i]);
    return ret;
  }
};
int main() {
  int n;
  cin >> n;
  vector<vec2> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].val;
    arr[i].idx = i;
  }
  Solution sol;
  auto ret = sol.solve(arr, n);
  cout << ret << endl;
}
