#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int MAXN = 2005;
pair<ll, int> a[MAXN];

int n;
ll memo[MAXN][MAXN];

ll dp(int L, int R) {
    if(L > R) return 0;
    if(memo[L][R] != -1) return memo[L][R];
    int i = L + (n-1-R);
    ll& ans = memo[L][R];
    ll on_left = a[i].first * abs(a[i].second - L);
    ll on_right = a[i].first * abs(a[i].second - R);
    ans = max(on_left + dp(L+1, R), on_right + dp(L, R-1));
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(memo, -1, sizeof memo);

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a, a+n);
    reverse(a, a+n);
    cout << dp(0, n-1) << endl;
}
