#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int MOD = 1000000007;
ll dp[2010][2010];
ll f1(ll in, ll i, int n, vector<pair<int, int>> &a) {
  if (in == a.size()) return 0;
  if (dp[in][i] != -1) return dp[in][i];
  int end = n - 1 - (in - i);
  ll ans1 = (a[in].first * (a[in].second - i)) + f1(in + 1, i + 1, n, a);
  ll ans2 = (a[in].first * (end - a[in].second)) + f1(in + 1, i, n, a);
  return dp[in][i] = max(ans1, ans2);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n, pair<int, int>());
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  memset(dp, -1, sizeof(dp));
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  ll ans = f1(0, 0, n, a);
  cout << ans << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
