#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  vector<long long> acc(N + 1, 0);
  for (int i = 1; i <= N; ++i) acc[i] = acc[i - 1] + A[i - 1];
  long long res = 0;
  for (int i = 0; i < N; ++i) {
    vector<pair<long long, int>> tmp_l, tmp_r;
    for (int j = 0; j <= i; ++j) tmp_l.emplace_back(A[j], j);
    for (int j = i + 1; j < N; ++j) tmp_r.emplace_back(A[j], j);
    long long tmp = 0;
    for (int j = 0; j <= i; ++j) {
      tmp += tmp_l[j].first * abs(tmp_l[j].second - (N - i - 1 + j));
    }
    for (int j = 0; j < tmp_r.size(); ++j)
      tmp += tmp_r[j].first * abs(tmp_r[j].second - j);
    res = max(res, tmp);
    tmp = 0;
    sort(tmp_l.begin(), tmp_l.end());
    for (int j = 0; j <= i; ++j) {
      tmp += tmp_l[j].first * abs(tmp_l[j].second - (N - i - 1 + j));
    }
    sort(tmp_r.begin(), tmp_r.end());
    reverse(tmp_r.begin(), tmp_r.end());
    for (int j = 0; j < tmp_r.size(); ++j)
      tmp += tmp_r[j].first * abs(tmp_r[j].second - j);
    res = max(tmp, res);
  }
  cout << res << endl;
  return 0;
}
