#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int N = 2e3 + 5;
int ord[N], a[N];
ll dp[N][N];
int n;

ll solve(int l, int r) {
    if (l > r) return 0;
    ll &ret = dp[l][r];
    if (ret != -1) return ret;
    int indx = ord[(l - 1) + (n - r) + 1];
    ret = max(solve(l + 1, r) + a[indx] * 1LL * abs(indx - l), solve(l, r - 1) + a[indx] * 1LL * abs(indx - r));
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ord[i] = i;
    }
    sort(ord + 1, ord + 1 + n, [](int i, int j) {
        return a[i] > a[j];
    });
    memset(dp, -1, sizeof(dp));
    cout << solve(1, n) << endl;

    return 0;
}