#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)

struct Problem {

    ULL dp[2001][2001] = {};

    void Solve() {
        LL N; cin >> N;
        vector<pair<ULL, LL>> A(N); 
        rep(i, N) {
            ULL a; cin >> a;
            A[i] = { a, i };
        }
        LL l = 0, r = N - 1;
        sort(A.rbegin(), A.rend());
        rep(i, N) {
            for (UL s = 0; s <= i; s++) {
                dp[s][s + N - i - 1] = max(dp[s][s + N - i - 1],
                    dp[s][s + N - i] + (A[i].first * abs(s + N - i - 1 - A[i].second)));
                dp[s + 1][s + N - i] = max(dp[s + 1][s + N - i],
                    dp[s][s + N - i] + (A[i].first * abs(s - A[i].second)));
            }
        }
        ULL ans = 0;
        rep(i, N + 1) ans = max(ans, dp[i][i]);
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}
