#include <bits/stdc++.h>
using namespace std;
long long ans;
long long ansa;
long long N;
pair<long long, long long> A[20005];
pair<long long, long long> B[20005];
pair<long long, long long> C[20005];
long long dp[25][25];
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long a;
    cin >> a;
    A[i] = pair<long long, long long>(a, i);
  }
  sort(A, A + N);
  for (int j = 1; j <= N; j++) {
    dp[0][j] = dp[0][j - 1] + A[N - j].first * (N - j - A[N - j].second);
  }
  for (int i = 1; i <= N; i++) {
    dp[i][0] = dp[i - 1][0] + A[N - i].first * (A[N - i].second - i + 1);
    for (int j = 1; j <= N; j++) {
      dp[i][j] = max(
          dp[i - 1][j] + A[N - i - j].first * (A[N - i - j].second - i + 1),
          dp[i][j - 1] + A[N - i - j].first * (N - j - A[N - i - j].second));
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans < dp[i][N - i]) {
      ans = dp[i][N - i];
    }
  }
  cout << ans << endl;
}
