#include <bits/stdc++.h>
using namespace std;
long long mil() { return numeric_limits<long long>::min(); }
long long mal() { return numeric_limits<long long>::max(); }
long long recur(long long l, long long r, long long i,
                vector<pair<long long, long long>> &ai,
                unordered_map<long long, long long> &cache) {
  if (i == ai.size()) {
    return 0;
  }
  long long key = l * 100 + r * 10 + i;
  auto val = cache.find(key);
  if (val != cache.end()) {
    return val->second;
  }
  auto &e = ai[i];
  long long ret =
      max(abs(e.second - l) * e.first + recur(l + 1, r, i + 1, ai, cache),
          abs(e.second - r) * e.first + recur(l, r - 1, i + 1, ai, cache));
  cache[key] = ret;
  return ret;
}
void solve() {
  int N;
  cin >> N;
  vector<pair<long long, long long>> ai(N);
  long long val = 0;
  for (long long i = 0; i < (N); ++i) cin >> val, ai[i] = make_pair(val, i);
  sort(ai.begin(), ai.end(), greater<pair<long long, long long>>());
  unordered_map<long long, long long> cache;
  long long sum = recur(0, ai.size() - 1, 0, ai, cache);
  cout << sum << endl;
}
int main(int argc, char **argv) { solve(); }
