#include <bits/stdc++.h>
int const MAXN = 2000;
int64_t A[MAXN];
int N, ix[MAXN];
int64_t iabs(int64_t i) { return std::max(i, -i); }
int main() {
  std::cin >> N;
  for (int i = 0; i < N; ++i) std::cin >> A[i];
  std::iota(ix, ix + N, 0);
  std::sort(ix, ix + N, [&](int l, int r) {
    return A[l] * std::max(l, N - 1 - l) > A[r] * std::max(r, N - 1 - r);
  });
  int64_t ans = 0;
  int im = 0, iM = N - 1;
  for (int i = 0; i < N; ++i) {
    if (ix[i] - im > iM - ix[i]) {
      ans += A[ix[i]] * (ix[i] - im);
      ++im;
    } else {
      ans += A[ix[i]] * (iM - ix[i]);
      --iM;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
