#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int N = 200005;
vector<pair<int, int> > v;
int memo[2000][2000];
ll solve(int *arr, int i, int l, int r) {
if (l == r) {
return v[i].first * (v[i].second - l);
}
if (memo[i][l] != -1) {
return memo[i][l];
}
int temp = n-1-(index-l);
ll ans1 = solve(arr, i + 1, l + 1, temp) + (v[i].first * abs(v[i].second - l));
ll ans2 = solve(arr, i + 1, l, temp - 1) + (v[i].first * abs(v[i].second - temp));
return memo[i][l] = max(ans1, ans2);
 
}
 
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 
int n;
cin >> n;
int arr[2005];
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i < n; i++) {
v.push_back({arr[i], i});
}
memset(memo, -1, sizeof memo);
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
// for (int i = 0; i < n; i++) {
// cout << v[i].first << " " << v[i].second << endl;
// }
cout << solve(arr, 0, 0, n - 1);
return 0;
 
}