#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  vector<pair<int64_t, int64_t>> a(n);
  for (int64_t i = 0; i < n; i++) {
    int64_t a_in;
    cin >> a_in;
    a.at(i) = make_pair(a_in, i);
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < n - 1; i++) {
    vector<pair<int64_t, int64_t>> a_mae;
    vector<pair<int64_t, int64_t>> a_usiro;
    for (int64_t j = 0; j < n; j++) {
      if (j <= i) {
        a_mae.push_back(a.at(j));
      } else {
        a_usiro.push_back(a.at(j));
      }
    }
    sort(a_mae.begin(), a_mae.end());
    sort(a_usiro.begin(), a_usiro.end());
    reverse(a_usiro.begin(), a_usiro.end());
    vector<pair<int64_t, int64_t>> a_after;
    a_after.insert(a_after.end(), a_usiro.begin(), a_usiro.end());
    a_after.insert(a_after.end(), a_mae.begin(), a_mae.end());
    int64_t temp = 0;
    for (int64_t i = 0; i < n; i++) {
      temp += a_after.at(i).first * abs(a_after.at(i).second - i);
    }
    ans = max(ans, temp);
  }
  cout << ans << endl;
}
