#include <bits/stdc++.h>
using namespace std;
static const long long max_h = 12;
static const long long max_w = 1010;
static const long long max_value = -10000000000;
static const long long max_num = 2010;
vector<pair<long long, long long>> infant_list(max_num);
vector<vector<long long>> dp(max_num, vector<long long>(max_num, 0));
long long ans = 0;
long long N;
int main() {
  long long A;
  scanf("%lld", &N);
  for (long long i = 0; i < N; i++) {
    scanf("%lld", &A);
    infant_list[i] = make_pair(i + 1, A);
  }
  sort(infant_list.begin(), infant_list.begin() + N,
       [](const pair<long long, long long>& x,
          const pair<long long, long long>& y) { return x.second > y.second; });
  dp[0][0] = 0;
  for (long long i = 1; i <= N; i++) {
    for (long long x = 0; x <= i; x++) {
      long long y = i - x;
      pair<long long, long long> last_infant = infant_list[i - 1];
      long long value_add_to_y = max_value, value_add_to_x = max_value;
      if (y > 0) {
        value_add_to_y =
            last_infant.second * (N - y + 1 - last_infant.first) + dp[x][y - 1];
      }
      if (x > 0) {
        value_add_to_x =
            last_infant.second * (last_infant.first - x) + dp[x - 1][y];
      }
      dp[x][y] = max(value_add_to_x, value_add_to_y);
    }
  }
  long long ans = max_value;
  for (long long i = 0; i <= N; i++) {
    ans = max(dp[i][N - i], ans);
  }
  printf("%lld\n", ans);
  return 0;
}
