#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = int(2e9);
const long long LINF = long long(2e9) * long long(2e9);
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<vector<long long>> score(N, vector<long long>(N));
  vector<pair<long long, pair<int, int>>> scoreidx;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      score[i][j] = A[i] * abs(i - j);
      scoreidx.push_back(make_pair(score[i][j], make_pair(i, j)));
    }
  }
  sort(scoreidx.begin(), scoreidx.end(),
       greater<pair<long long, pair<int, int>>>());
  unordered_set<int> already_src, already_dst;
  long long ans1 = 0;
  bool is_back = false;
  int j1 = 0, j2 = N - 1;
  for (int j = 0; j < N; j++) {
    int k;
    if (is_back == false) {
      k = j1;
      j1++;
      is_back = true;
    } else {
      k = j2;
      j2--;
      is_back = false;
    }
    long long max_s = 0;
    long long max_i = 0;
    for (int i = 0; i < N; i++) {
      if (already_src.count(i) > 0) continue;
      if (max_s < score[i][k]) {
        max_s = max(max_s, score[i][k]);
        max_i = i;
      }
    }
    ans1 += max_s;
    already_src.insert(max_i);
  }
  is_back = true;
  long long ans2 = 0;
  already_src.clear();
  j1 = 0;
  j2 = N - 1;
  for (int j = 0; j < N; j++) {
    int k;
    if (is_back == false) {
      k = j1;
      j1++;
      is_back = true;
    } else {
      k = j2;
      j2--;
      is_back = false;
    }
    long long max_s = 0;
    long long max_i = 0;
    for (int i = 0; i < N; i++) {
      if (already_src.count(i) > 0) continue;
      if (max_s < score[i][k]) {
        max_s = max(max_s, score[i][k]);
        max_i = i;
      }
    }
    ans2 += max_s;
    already_src.insert(max_i);
  }
  cout << max(ans1, ans2) << endl;
  return 0;
}
