#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using P = pair<ll, int>;
int main() {
  int n;
  cin >> n;
  P a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    ll sum = 0;
    vector<P> buf(a, a + n);
    sort(buf.begin(), buf.begin() + i, greater<P>());
    sort(buf.begin() + i, buf.end(), greater<P>());
    if (i * 2 > n) {
      bool check[n];
      fill(check, check + i, false);
      fill(check + i, check + n, true);
      int id = 0;
      for (int j = 0; j < i; j++) {
        if (j < n - 1 && !check[n - j - 2]) {
          sum += buf[n - j - 2].first;
          check[n - j - 2] = true;
        } else {
          while (check[id]) id++;
          sum += buf[id].first * abs(n - j - 1 - buf[id].second);
          check[id] = true;
        }
      }
      for (int j = i; j < n; j++) {
        sum += buf[j].first * abs(j - i - buf[j].second);
      }
    } else {
      for (int j = 0; j < i; j++) {
        sum += buf[j].first * abs(n - j - 1 - buf[j].second);
      }
      bool check[n];
      fill(check, check + i, true);
      fill(check + i, check + n, false);
      int id = i;
      for (int j = i; j < n; j++) {
        if (j - i < n - 1 && !check[j - i + 1]) {
          sum += buf[j - i + 1].first;
          check[j - i + 1] = true;
        } else {
          while (check[id]) id++;
          sum += buf[id].first * abs(j - i - buf[id].second);
          check[id] = true;
        }
      }
    }
    ans = max(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}
