#include <bits/stdc++.h>
using namespace std;
const int MAX = 2020;
int N;
int A[MAX];
long long dp[MAX][MAX];
long long solve() {
  vector<pair<long long, long long> > a;
  for (long long i = 0; i < N; ++i)
    a.push_back(pair<long long, long long>(A[i], i));
  sort(a.rbegin(), a.rend());
  for (long long i = 0; i < N; ++i) {
    dp[i + 1][0] = dp[i][0] + a[i].first * (a[i].second - i);
    dp[0][i + 1] = dp[0][i] + a[i].first * (N - 1 - i - a[i].second);
  }
  for (long long k = 2; k < N + 1; ++k) {
    for (long long i = 1; i < k; ++i) {
      dp[i][k - i] =
          max(dp[i][k - i],
              dp[i - 1][k - i] + a[k - 1].first * (a[k - 1].second - i + 1));
      dp[i][k - i] =
          max(dp[i][k - i], dp[i][k - i - 1] +
                                a[k - 1].first * (N - k + i - a[k - 1].second));
    }
  }
  long long ret = 0;
  for (long long i = 0; i < N + 1; ++i) ret = max(ret, dp[i][N - i]);
  return ret;
}
int main() {
  cin >> N;
  for (long long i = 0; i < N; ++i) cin >> A[i];
  cout << solve() << endl;
}
