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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2002;

int n , dp[N][N];
pair<int , int> arr[2002];

int ans(int idx , int start , int end) {
    if(end < start) return 0;
    int& get = dp[idx][start];
    if(get != -1) return dp[idx][start];
    get = max((arr[idx].first * abs(arr[idx].second - start)) + ans(idx + 1 , start + 1 , end) , (arr[idx].first * abs(arr[idx].second - end)) + ans(idx + 1 , start , end - 1));
    return get;
}
void solve() {
    memset(dp , -1 , sizeof dp);
    cin >> n;
    for(int i = 0 ; i < n ; i ++) cin >> arr[i].first , arr[i].second = i;
    sort(arr , arr + n);
    reverse(arr , arr + n);
    int q = ans(0 , 0 , n - 1);
    cout << q;
}

/*
 */

int main()
{
    fastio
    int testcase = 1;
    //cin >> testcase ;
    
    while(testcase --) {
        solve();
        cout << '\n';
    }
    
    return 0;
}
 

