#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
void Main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<P> ord;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    ord.emplace_back(A[i], i);
  }
  ll dp[n + 1][n + 1];
  memset(dp, 0, sizeof(dp));
  sort(ord.begin(), ord.end());
  for (int i = 0; i < (int)n; ++i) {
    for (int l = 0; l < (int)n - i + 1; ++l) {
      int r = l + i;
      const auto &[a, pos] = ord[i];
      dp[i + 1][l] =
          max(dp[i][l] + a * abs(pos - r), dp[i][l + 1] + a * abs(pos - l));
    }
  }
  cout << dp[n][0] << endl;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
