#include <bits/stdc++.h>
using namespace std;
int fun(vector<int> vec, int id, vector<int> vis, int n,
        map<int, map<vector<int>, int> > &dp) {
  if (id == n) {
    return 0;
  }
  if (dp[id][vis] != 0) return dp[id][vis];
  int ma = INT_MIN;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      vis[i] = 1;
      ma = max(ma, vec[id] * abs(i - id) + fun(vec, id + 1, vis, n, dp));
      vis[i] = 0;
    }
  }
  return dp[id][vis] = ma;
}
int main() {
  int n;
  cin >> n;
  vector<int> ar;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ar.push_back(a);
  }
  map<int, map<vector<int>, int> > dp;
  vector<int> visi(n + 1, 0);
  cout << fun(ar, 0, visi, n, dp);
  return 0;
}
