#include <bits/stdc++.h>
using namespace std;
long N;
long ans(vector<pair<long, long> > V, long s) {
  long i, n = V.size();
  if (n == 1) {
    return abs(s - V[0].second) * V[0].first;
  }
  long u = 0, v = 0, m = 0;
  for (i = 0; i < n; i++) {
    u = max(abs(s - V[i].second), abs(N - (N - n - s) - 1 - V[i].second)) *
        V[i].first;
    if (v < u) {
      m = i;
      v = u;
    }
  }
  long l = abs(s - V[m].second), r = abs(N - (N - n - s) - 1 - V[m].second);
  vector<pair<long, long> > W;
  for (i = 0; i < n; i++) {
    if (i != m) {
      W.push_back(V[i]);
    }
  }
  if (l == r) {
    return v + max(ans(W, s), ans(W, s + 1));
  } else if (l > r) {
    return v + ans(W, s + 1);
  } else {
    return v + ans(W, s);
  }
}
int main() {
  long A, i;
  cin >> N;
  vector<pair<long, long> > V;
  for (i = 0; i < N; i++) {
    cin >> A;
    V.push_back(make_pair(A, i));
  }
  cout << ans(V, 0) << "\n";
}
