#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool chosen[2001];
long long n, ar[2001];
long long dp[2001][2001] = {-1};
void myfunc() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = ar[i] * abs(j - i);
    }
  }
}
long long sum = 0, max1 = -1;
void recur(int x) {
  if (x >= n) return;
  for (int i = 0; i < n; i++) {
    if (chosen[i] == false) {
      chosen[i] = true;
      sum += dp[x][i];
      recur(x + 1);
      max1 = max(max1, sum);
      sum -= dp[x][i];
      chosen[i] = false;
    }
  }
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i += 1) cin >> ar[i];
  myfunc();
  recur(0);
  cout << max1;
}
int main() {
  fastio();
  solve();
  return 0;
  int t, k = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
