#include <bits/stdc++.h>
using namespace std;
vector<int> A;
long long f(int i, vector<bool>& vis) {
  if (i >= A.size()) {
    return 0;
  }
  long long sum = 0;
  for (int j = 0; j < A.size(); j++) {
    if (j != i && vis[j] == false) {
      vis[j] = true;
      sum = max(sum, A[i] * abs(j - i) + f(i + 1, vis));
      vis[j] = false;
    }
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  A = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  vector<bool> vis(n);
  cout << f(0, vis);
  return 0;
}
