#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<vector<int>> B(N, vector<int>(2));
  vector<int> C(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  long long sum = 0;
  int size = N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < size; j++) {
      B.at(j).at(0) =
          max(A.at(j) * abs(N - (j + 1)), A.at(j) * abs(1 - (j + 1)));
      B.at(j).at(1) = j;
      C.at(j) = B.at(j).at(0);
    }
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());
    sum += C.at(0);
    sort(C.begin(), C.end());
    C.pop_back();
    B.pop_back();
    size--;
  }
  cout << sum << endl;
}
