#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> table;
  for (int i = 0; i < n; i += 1) {
    int a;
    cin >> a;
    table.push_back({a, i + 1});
  }
  sort(table.rbegin(), table.rend());
  long long dp[n + 1][n + 1];
  dp[0][0] = 0;
  int i = 0;
  for (pair<int, int> p : table) {
    i++;
    if (i == 1) {
      dp[1][0] = p.first * abs(p.second - n);
      dp[1][1] = p.first * abs(p.second - 1);
      continue;
    }
    for (int j = 0; j < i + 1; j += 1) {
      if (j == 0) {
        dp[i][j] = dp[i - 1][0] + p.first * abs(p.second - n + (i - 1));
      } else if (j == i) {
        dp[i][j] = dp[i - 1][j - 1] + p.first * abs(p.second - j);
      } else {
        long long m1, m2;
        m1 = dp[i - 1][j - 1] + p.first * abs(p.second - j);
        m2 = dp[i - 1][j] + p.first * abs(p.second - n + (i - 1 - j));
        dp[i][j] = max(m1, m2);
      }
    }
  }
  long long ans = dp[n][1];
  for (int i = 1; i < n + 1; i += 1) {
    if (dp[n][i] > ans) {
      ans = dp[n][i];
    }
  }
  cout << ans << endl;
  return 0;
}
