#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long A[2001];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool Done[2001];
  for (int i = 0; i < N; i++) {
    Done[i] = false;
  }
  long long ans = 0;
  int left_ = 0;
  int right_ = N - 1;
  for (int j = 0; j < N; j++) {
    int ii = -1;
    long long EAMAX = -1;
    for (int i = 0; i < N; i++) {
      long long EA;
      if (!Done[i]) {
        EA = A[i] * (max(abs(i - left_), abs(i - right_)));
        if (EAMAX < EA) {
          EAMAX = EA;
          ii = i;
        }
      }
    }
    if (abs(ii - left_) > abs(ii - right_)) {
      left_++;
    } else {
      right_--;
    }
    Done[ii] = true;
    ans += EAMAX;
  }
  cout << ans << endl;
  return 0;
}
