#include <bits/stdc++.h>
using namespace std;
long long get_score(vector<long long> &va, vector<long long> &vp) {
  long long ans = 0;
  for (long long i = 0; i < va.size(); i++) {
    ans += abs(i - vp[i]) * va[i];
  }
  return ans;
}
long long get_ans(vector<long long> &va, vector<bool> &v_used, long long l,
                  long long r) {
  if (l > r) {
    return 0;
  }
  priority_queue<pair<long long, long long>> q;
  for (long long i = 0; i < v_used.size(); i++) {
    if (!v_used[i]) {
      long long tmp_score = va[i] * max(abs(i - l), abs(i - r));
      q.push(pair<long long, long long>(tmp_score, i));
    }
  }
  long long max_score = q.top().first;
  priority_queue<long long> q_ans;
  while (!q.empty() && q.top().first == max_score) {
    long long place = q.top().second;
    q.pop();
    if (abs(place - l) < abs(place - r)) {
      v_used[place] = true;
      q_ans.push(get_ans(va, v_used, l, r - 1) + max_score);
      v_used[place] = false;
    } else if (abs(place - l) > abs(place - r)) {
      v_used[place] = true;
      q_ans.push(get_ans(va, v_used, l + 1, r) + max_score);
      v_used[place] = false;
    } else {
      v_used[place] = true;
      q_ans.push(get_ans(va, v_used, l, r - 1) + max_score);
      v_used[place] = false;
      v_used[place] = true;
      q_ans.push(get_ans(va, v_used, l + 1, r) + max_score);
      v_used[place] = false;
    }
  }
  return q_ans.top();
}
signed main() {
  long long N;
  cin >> N;
  vector<long long> va(N);
  for (long long i = 0; i < N; i++) {
    cin >> va[i];
  }
  long long l = 0, r = N - 1;
  vector<bool> v_used(N, false);
  cout << get_ans(va, v_used, l, r) << endl;
}
