#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N;
  cin >> N;
  vector<pair<ll,ll>> A(N);
  rep(i, N) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(all(A));
  reverse(all(A));
  
  vector<vector<ll>> dp(N+1, vector<ll>(N+3));
  
  rep(i, N) rep2(j, i+1) {
    dp[i+1][j] = max(dp[i][j-1] + A[i].first * (A[i].second - (j-1)),
                     dp[i][j] + A[i].first * (N-1-i+j - A[i].second)
                    );
    dp[i+1][j+1] = max(dp[i][j] + A[i].first * (A[i].second - j),
                       dp[i][j+1] + A[i].first * (N-1-i+j+1 - A[i].second)
                       );
    }
  }

  ll ans = 0;
  rep2(i, N+1) ans = max(ans, dp[N][i]);
  cout << ans << '\n';
  return 0;
}
