#include <bits/stdc++.h>
using namespace std;
long long N;
pair<long long, long long> A[2000];
long long dp[2001][2001];
long long happiness(long long i, long long to) {
  return abs(A[i].second - to) * A[i].first;
}
signed main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A, A + N, greater<pair<long long, long long>>());
  dp[0][1] = happiness(0, N - 1);
  dp[1][0] = happiness(0, 0);
  long long ans = 0;
  for (long long x = 1; x <= N; x++)
    for (long long y = 1; y <= N - x; y++) {
      dp[x][y] = max(dp[x - 1][y] + happiness(x + y - 1, x - 1),
                     dp[x][y - 1] + happiness(x + y - 1, N - 1 - y + 1));
      ans = max(ans, dp[x][y]);
    }
  cout << ans << endl;
}
