#include <bits/stdc++.h>
using namespace std;
long long n;
std::vector<long long> a(2007);
std::map<set<long long>, long long> dp[2007];
long long res = 0;
long long func(long long pos, set<long long> taken, long long ts) {
  if (pos == (n + 1)) {
    res = max(res, ts);
    return dp[pos][taken] = max(dp[pos][taken], ts);
  }
  long long cres = 0;
  for (long long int i = 1; i < n + 1; i++) {
    if (taken.find(i) == taken.end()) {
      taken.insert(i);
      long long ex = abs(pos - i) * a[pos];
      cres = max(cres, func(pos + 1, taken, ts + ex));
      taken.erase(i);
    }
  }
  return dp[pos][taken] = max(dp[pos][taken], cres);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> a[i + 1];
  set<long long> pos;
  func(1, pos, 0);
  cout << res;
}
