#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
const long long nax = 1e5 + 7;
const long long mod = 1e9 + 7;
const long long inf = numeric_limits<long long>::max();
long long n, m;
map<tuple<long long, long long, long long>, long long> dp;
vector<pair<long long, long long>> p;
long long maxdp(long long i, long long s, long long e) {
  if (i == n) return 0;
  auto ths = make_tuple(i, s, e);
  if (dp.find(ths) != dp.end()) return dp[ths];
  long long in = p[i].second;
  long long left = p[i].first * (abs(s - in));
  long long right = p[i].first * (abs(e - in));
  return dp[ths] =
             max(left + maxdp(i + 1, s + 1, e), right + maxdp(i + 1, s, e - 1));
}
void test() {
  cin >> n;
  p.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(p.begin(), p.end(), greater<pair<long long, long long>>());
  cout << maxdp(0, 0, n - 1);
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  while (T--) {
    test();
    cout << "\n";
  }
  return 0;
}
