#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5;
const long long INF = 1e18L;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
long long ar[N];
long long dp[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    long long n;
    cin >> n;
    vector<long long> v, p;
    for (long long i = 1; i <= n; i++) {
      cin >> ar[i];
      v.push_back(i);
      p.push_back(i);
    }
    long long ans = 0, cur = 0;
    long long cnt = 10000;
    while (cnt--) {
      random_shuffle(v.begin(), v.end());
      cur = 0;
      for (long long i = 1; i <= n; i++) {
        cur += ar[i] * (abs(i - v[i - 1]));
      }
      ans = max(ans, cur);
      v = p;
    }
    cout << ans;
  }
  cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
  return 0;
}
