    #include<bits/stdc++.h>
    using namespace std;
    
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
    #define int long long 
    #define double long double
    
    #define all(a)      (a).begin(),(a).end()
    #define sz(x)       (int)x.size()
    
    #define ff first
    #define ss second
    #define mp make_pair
         
    #define pb push_back
    #define endl "\n" 
         
    #define f(i,l,r) for(int i=l;i<=r;i++)
    #define rf(i,r,l) for(int i=r;i>=l;i--)    

    #define bp __builtin_popcountll
    #define inf 3e18
    
    const int N=1e5+5; 
    const int M=1e9+7;
    #define pi 3.14159265359
    int modularExponentiation(int x,int n,int M)
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int n;
vector<pair<int,int>> arr;
static unsigned generate_key() {
	static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned t = x ^ x<<11;
	x = y; y = z; z = w;
	return w = w ^ w>>19 ^ t ^ t>>8;
}
void shuffle(vector<pair<int,int>> &vec){
	int n = vec.size();
	for(int i = 0; i < n; i++){
		int p = i + (generate_key() % (n - i));
		swap(vec[i], vec[p]);
	}
}

    void solve()
    {
    	cin>>n;
    	arr.resize(n);
    	f(i,0,n-1) cin>>arr[i].ff,arr[i].ss=i;
    	int ans=0;
    	srand(time(NULL));
    	f(i,1,5000)
    	{
    		shuffle(arr);

	    		int tt=0;
    		f(j,0,n-1)
    		{
    			//cout<<arr[j].ff<<" ";
    			tt+=abs(arr[j].ss-j)*arr[j].ff;
    		}
    		//cout<<endl;
    		ans=max(ans,tt);
    	}
    	cout<<ans;
    	
    	
    }
      signed main()  
    {
        FAST
        int t=1;
        // cin>>t;
        for(int tc=1;tc<=t;tc++)
        {
    		// cout<<"Case #"<<tc<<": ";
    		solve();
        }
    }

