#include <bits/stdc++.h>
using namespace std;
long long MOD = 10000000000 + 7;
bool compare(pair<long long, int> x, pair<long long, int> y) {
  return x.first > y.first;
}
int main() {
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<pair<long long, int>> v(N);
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    v.at(i) = make_pair(tmp, i);
  }
  sort(v.begin(), v.end(), compare);
  vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
  for (int k = 1; k <= N; k++) {
    for (int i = 0; i <= k; i++) {
      int j = k - i;
      if (i - 1 >= 0)
        dp[i][j] =
            max(dp[i][j],
                dp[i - 1][j] + v[k - 1].first * abs(v[k - 1].second - i + 1));
      if (j - 1 >= 0)
        dp[i][j] =
            max(dp[i][j],
                dp[i][j - 1] + v[k - 1].first * abs(N - j - v[k - 1].second));
    }
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, dp.at(i).at(N - i));
  }
  cout << ans << endl;
}
