#include <bits/stdc++.h>
using namespace std;
long long solve(long long l, long long r, vector<pair<long long, bool>> &v) {
  if (!(l <= r)) {
    return 0;
  }
  priority_queue<pair<long long, pair<long long, bool>>> q;
  for (long long i = 0; i < v.size(); i++) {
    if (!v[i].second) {
      q.push(pair<long long, pair<long long, bool>>(
          v[i].first * abs(l - i), pair<long long, bool>(i, true)));
      q.push(pair<long long, pair<long long, bool>>(
          v[i].first * abs(r - i), pair<long long, bool>(i, false)));
    }
  }
  long long ans = q.top().first;
  priority_queue<long long> tmp_ans;
  while (!q.empty() && q.top().first == ans) {
    bool is_left = q.top().second.second;
    long long index = q.top().second.first;
    v[index].second = true;
    if (is_left) {
      tmp_ans.push(ans + solve(l + 1, r, v));
    } else {
      tmp_ans.push(ans + solve(l, r - 1, v));
    }
    v[index].second = false;
    q.pop();
  }
  return tmp_ans.top();
}
signed main() {
  long long N;
  cin >> N;
  vector<pair<long long, bool>> v(N);
  for (long long i = 0; i < N; i++) {
    cin >> v[i].first;
    v[i].second = false;
  }
  long long l = 0;
  long long r = N - 1;
  cout << solve(l, r, v) << endl;
}
