#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<int> A;
vector<int> used;
ll ans = 0;
ll tans = 0;
int N;
void dfs(int ni) {
  if (ni == N) {
    ans = max(ans, tans);
    return;
  }
  for (int i = 0; i < (N); ++i) {
    if (used[i]) continue;
    used[i] = 1;
    tans += A[i] * abs(ni - i);
    dfs(ni + 1);
    tans -= A[i] * abs(ni - i);
    used[i] = 0;
  }
  return;
}
int main() {
  cout << fixed << setprecision(10);
  cin >> N;
  A.resize(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  used.resize(N);
  dfs(0);
  cout << ans << endl;
  return 0;
}
