#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<pair<int, int> > D;
  for (int i = 0; i < N; ++i) {
    pair<int, int> data = make_pair(A[i], i);
    D.push_back(data);
  }
  set<pair<int, int> > s;
  set<pair<int, int> > t;
  for (int i = 0; i < N; ++i) {
    t.insert(D[i]);
  }
  long long max_score = 0;
  for (int k = 0; k < N - 1; ++k) {
    pair<int, int> data = make_pair(A[k], k);
    s.insert(data);
    t.erase(data);
    long long score = 0;
    int j = 0;
    for (auto it = t.rbegin(); it != t.rend(); ++it) {
      int A = it->first;
      int i = it->second;
      score += long long(A) * abs(i - j);
      ++j;
    }
    for (auto it = s.begin(); it != s.end(); ++it) {
      int A = it->first;
      int i = it->second;
      score += long long(A) * abs(i - j);
      ++j;
    }
    max_score = max(max_score, score);
  }
  cout << max_score << endl;
  return 0;
}
