#include <bits/stdc++.h>
using namespace std;
map<string, long long> dp;
string state;
long long rec(long long ind, vector<long long> &arr, long long n,
              long long rearranged) {
  if (rearranged == n) return 0;
  if (dp.find(state) != dp.end()) return dp[state];
  long long res = INT_MIN;
  for (long long i = 0; i < n; i++) {
    if (state[i] == '0') {
      state[i] = '1';
      res = max(res,
                abs(ind - i) * arr[ind] + rec(ind + 1, arr, n, rearranged + 1));
      state[i] = '0';
    }
  }
  dp[state] = res;
  return dp[state];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j;
  cin >> n;
  vector<long long> arr(n);
  for (i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    arr[i] = temp;
  }
  for (i = 0; i <= n; i++) state.push_back('0');
  cout << rec(0, arr, n, 0) << endl;
  return 0;
}
