#include <bits/stdc++.h>
using namespace std;
void File() {}
void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const long long oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 2e3 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
int dp[nn][nn];
vector<pair<int, int> > vec;
int n;
int solve(int l, int r) {
  if (l > r) return 0;
  if (l == r) return vec[n].first * abs(vec[n].second - l);
  int &res = dp[l][r];
  if (res != -1) return res;
  int x = n - (r - l + 1) + 1;
  res = 0;
  res = max(res, (vec[x].first * (abs(vec[x].second - l))) + solve(l + 1, r));
  res = max(res, (vec[x].first * (abs(vec[x].second - r))) + solve(l, r - 1));
  return res;
}
int main() {
  fast();
  cin >> n;
  int arr[nn];
  vec.push_back(make_pair(0, 0));
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    vec.push_back(make_pair(arr[i], i));
  }
  sort(vec.begin() + 1, vec.end());
  reverse(vec.begin() + 1, vec.end());
  memset(dp, -1, sizeof(dp));
  cout << solve(1, n) << "\n";
  return 0;
}
