#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
//#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 
vector<PIPI>re;int n;
map<pair<int,pair<string,string>>,bool>vis;
map<pair<int,pair<string,string>>,int>dp;
int solve(int i,string x1,string  x2)
{
    int flag=0;
    for(int i=0;i<n;i++)if(x1[i]=='0')flag=1;
    if(flag==0)return 0;
    if(i==re.size())return NINF;
    if(vis[{i,{x1,x2}}]==false)
    {vis[{i,{x1,x2}}]=true;
    int ans=solve(i+1,x1,x2);
    if(x1[re[i].SE.FI]=='0'&&x2[re[i].SE.SE]=='0')
    {
        x1[re[i].SE.FI]='1';x2[re[i].SE.SE]='1';
        ans=max(ans,re[i].FI+solve(i+1,x1,x2));
         x1[re[i].SE.FI]='0';x2[re[i].SE.SE]='0';
    }
    dp[{i,{x1,x2}}]=ans;
    }
    return dp[{i,{x1,x2}}];
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    
    cin>>n;int ans=0;VI ar(n);
    string x1="",x2="";
    for(int i=0;i<n;i++)
    {cin>>ar[i];x1+='0';x2+='0';
     for(int j=0;j<n;j++)
     {
         re.pb({ar[i]*abs(i-j),{i,j}});
     }
    }
    sort(all(re),greater<PIPI>());
    ans=solve(0,x1,x2);
    cout<<ans<<endl;
    
    
}


return 0;
}



