#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
long long int dp[1001][1001];
long long int solve(long long int idx, long long int us,
                    vector<pair<long long int, long long int>> vect) {
  if (idx == vect.size()) {
    return 0;
  }
  if (dp[idx][us] != -1) return dp[idx][us];
  long long int ans = abs(vect[idx].second - us) * vect[idx].first +
                      solve(idx + 1, us + 1, vect);
  ans = max(ans, abs(vect[idx].second -
                     ((long long int)vect.size() - (idx - us) - 1)) *
                         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));
    long long int n, i, j;
    cin >> n;
    priority_queue<pair<long long int, pair<long long int, long long int>>> pq;
    vector<pair<long long int, long long int>> vect;
    long long int st, en;
    long long int dp[n][n];
    long long 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());
    reverse(vect.begin(), vect.end());
    long long int ans = solve(0, 0, vect);
    cout << ans << endl;
  }
  return 0;
}
