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