#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() {
  cerr << "cpu time : " << double(clock()) / CLOCKS_PER_SEC << "\n";
  return;
}
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int, int>;
void solve() {
  int n;
  cin >> n;
  vector<pii> a(n);
  for (decltype(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    a[i].first = i;
    cin >> a[i].second;
  }
  sort((a).begin(), (a).end());
  ull ans = 0, maxi = 0;
  do {
    maxi = 0;
    for (decltype(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      maxi += a[i].second * abs(a[i].first - i);
    }
    ans = max(ans, maxi);
  } while (next_permutation((a).begin(), (a).end()));
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  while (t--) {
    solve();
  }
  cpuTime();
  return 0;
}
