#include <bits/stdc++.h>
using namespace std;
std::vector<pair<int, int> > v;
int n;
int ans[2005][2005];
long long int val = 0;
long long int sol = 0;
int dp(int l, int r) {
  int k = (r - l + 1);
  if (l == r) {
    return v[k].first * abs(r - v[k].second);
  } else {
    if (ans[l][r] == -1) {
      long long int len;
      len = max(v[k].first * abs(l - v[k].second) + dp(l + 1, r),
                v[k].first * abs(r - v[k].second) + dp(l, r - 1));
      ans[l][r] = len;
      return len;
    } else
      return ans[l][r];
  }
}
int main() {
  memset(ans, -1, sizeof(ans));
  int y;
  cin >> n;
  v.push_back(make_pair(INT_MIN, 0));
  for (int i = 1; i <= n; i++) {
    cin >> y;
    v.push_back(make_pair(y, i));
  }
  sort(v.begin(), v.end());
  cout << dp(1, n);
}
