#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
#if !defined(ONLINE_JUDGE)
#include "debugging.h"
#endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
// int const mod = 998244353;
int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 1e5+5;
int const inf = 2e16;

bool cmp(pii a,pii b){
    return a.second < b.second;
}

void solve(){  
    int i,j;
    int n;
    cin>>n;
    int ans = 0;
    vector<pii> a;
    for(i=0;i<n;i++){
        int x; cin>>x; a.pb({x,i});
    }
    {
        sort(all(a));
        int tmp = 0;
        for(i=0;i<n;i++){
            tmp = tmp + a[i].first*(abs(a[i].second - i));
        }
        ans = max(ans , tmp);
        // dbg(a);
        // cout<<ans<<endl;
    }
    for(i=0;i<n;i++){
        vector<pii> b,c;
        sort(all(a) , cmp);
        for(j=0;j<=i;j++){
            b.pb(a[j]);
        }
        for(;j<n;j++){
            c.pb(a[j]);
        }
        sort(all(b));
        sort(all(c));
        reverse(all(c));

        int sm = 0;
        // dbg(b);
        // dbg(c);
        int l = n-1-i;
        for(j=0;j<b.size();j++){
            sm = sm + b[j].first*(abs((l) - b[j].second));
            l++;
        }
        for(j=0;j<c.size();j++){
            sm = sm + c[j].first*(abs(j - c[j].second));
        }

        ans = max(ans , sm);
    }
    cout<<ans<<endl;
}             


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*


*/