#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cout << setprecision(10) << fixed;
  int n;
  cin >> n;
  vector<pair<long long, int>> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin() + 1, a.end());
  reverse(a.begin() + 1, a.end());
  vector<vector<long long>> dp(n + 2, vector<long long>(n + 2, 0));
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      long long x = a[i].first;
      long long l = abs(a[i].second - (i - j));
      long long r = abs((n - j) - a[i].second);
      dp[i][j] = max(dp[i][j], dp[i - 1][j] + x * l);
      dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + x * r);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}
