#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using edge = struct {
  int to;
  long long cost;
};
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
}
template <class t, class u>
void chmin(t& a, u b) {
  if (b < a) a = b;
}
int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  long long sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  vector<int> al(N, 0);
  long long itr = 0;
  for (int i = 0; i < N; i++) {
    long long max = 0;
    if (i % 2 == 0) {
      for (int j = 0; j < N; j++) {
        if (max <= a[j] * abs(i / 2 - j) && al[j] == 0) {
          max = a[j] * abs(i / 2 - j);
          itr = j;
        }
      }
      sum += max;
      al[itr] = 1;
      max = 0;
    } else {
      for (int j = 0; j < N; j++) {
        if (max <= a[j] * abs(N - i / 2 - 1 - j) && al[j] == 0) {
          max = a[j] * abs(N - i / 2 - 1 - j);
          itr = j;
        }
      }
      sum += max;
      al[itr] = 1;
      max = 0;
    }
  }
  cout << sum << endl;
}
