#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
const int M = 500;
const int MOD = 1e9 + 7;
const int alpha = 26;
const double PI = acos(-1);
long long n, k;
long long ans = 0;
long long a[N];
pair<long long, long long> b[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = {a[i], i};
  }
  sort(b, b + n);
  reverse(b, b + n);
  vector<long long> dp(n);
  for (int j = 0; j < n; j++) {
    vector<long long> dp2(n + 1);
    for (int i = 0; i < n; i++) {
      int L = i;
      int R = n - 1 - j + i;
      if (0 <= L && R < n && L <= R) {
        dp2[i + 1] = max((long long)dp2[i + 1],
                         dp[i] + abs(L - b[j].second) * b[j].first);
        dp2[i] =
            max((long long)dp2[i], dp[i] + abs(R - b[j].second) * b[j].first);
      }
    }
    for (int i = 0; i <= n; i++) cout << dp2[i] << " ";
    dp = dp2;
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, (long long)dp[i]);
  cout << ans;
}
