#include <bits/stdc++.h>
using namespace std;
long long int solve(long long int in, long long int index,
                    vector<vector<long long int> > &dp, vector<bool> &vis) {
  if (in == vis.size() - 1)
    return 0;
  else {
    long long int minn = -1;
    for (int i = 0; i < vis.size(); i++) {
      if (!vis[i]) {
        vis[i] = true;
        minn = max(minn, solve(in + 1, i, dp, vis) + dp[in + 1][i]);
        vis[i] = false;
      }
    }
    return minn;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<long long int> > dp(n, vector<long long int>(n, -1));
  vector<bool> vis(n, false);
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      dp[j][i] = a[j] * (abs(j - i));
    }
  }
  long long int sum = -1;
  for (int i = 0; i < n; i++) {
    vis[i] = true;
    sum = max(sum, solve(0, i, dp, vis) + dp[0][i]);
    vis[i] = false;
  }
  cout << sum << endl;
}
