#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int n;
int dp[2005][2005];
int solve(int idx, int us, vector<pair<int, int>>& vect) {
  if (idx == n) {
    return 0;
  }
  if (dp[idx][us] != -1) return dp[idx][us];
  int ans = (abs(vect[idx].second - us) * vect[idx].first) +
            solve(idx + 1, us + 1, vect);
  int jv = n - 1 - (idx - us);
  ans = max(ans, (abs(vect[idx].second - jv) * vect[idx].first) +
                     solve(idx + 1, us, vect));
  dp[idx][us] = ans;
  return ans;
}
int main() {
  fastio();
  long long int T;
  T = 1;
  while (T--) {
    memset(dp, -1, sizeof(dp));
    int i, j;
    cin >> n;
    vector<pair<int, int>> vect;
    int st, en;
    int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      vect.push_back(make_pair(a[i], i));
    }
    sort(vect.begin(), vect.end(), greater<pair<int, int>>());
    int ans = solve(0, 0, vect);
    cout << ans << endl;
  }
  return 0;
}
