#include <bits/stdc++.h>
using namespace std;
const int N=2000+5;
int f[N][N]={0};
int n;
int a[N];
int main(){
freopen ("treats.in","r",stdin);
freopen ("treats.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);
for (int i=1;i<=n;i++){
for (int j=0;j<=i;j++){
f[i][j]=max(f[i-1][j]+i*a[n-(i-j)+1],f[i-1][j-1]+i*a[j]);
}
}
int ans=0;
for (int i=0;i<=n;i++){
ans=max(ans,f[n][i]);
}
printf("%d\n",ans);
return 0;
}