#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > ar;
long long mx = 0;
void printArr(long long n) {
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans = ans + (ar[i].first * abs(ar[i].second - i));
  }
  mx = max(mx, ans);
}
void heapPermutation(long long sz, long long n) {
  if (sz == 1) {
    printArr(n);
    return;
  }
  for (long long i = 0; i < sz; i++) {
    heapPermutation(sz - 1, n);
    if (sz % 2 == 1)
      swap(ar[0], ar[sz - 1]);
    else
      swap(ar[i], ar[sz - 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, a;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    ar.push_back({a, i});
  }
  heapPermutation(n, n);
  cout << mx << endl;
  return 0;
}
