#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=100010; const double err=1e-11; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
int a[N],to[N];
int now=0,ans=0;
int n;
priority_queue<pii,vector<pii>,greater<pii>> q;
signed main(){
	cin>>n;
	repeat(i,0,n)cin>>a[i];
	repeat(i,0,n+1){//orz(to_string(i));
		now=0;
		repeat(j,0,n){
			if(j<i)q.push({a[j],j});
			if(j>=n-i)
				now+=q.top().fi*abs(j-q.top().se),q.pop();
		}
		repeat_back(j,0,n){
			if(j>=i)q.push({a[j],j});
			if(j<n-i)
				now+=q.top().fi*abs(j-q.top().se),q.pop();
		}
		ans=max(now,ans);
	}
	cout<<ans<<endl;
	return 0;
}