#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const long long INF = 10e17;
double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }
std::istream &operator>>(std::istream &in, set<int> &o) {
  long long a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
const int mod = 1000000007;
struct Infant {
  long long index;
  long long active;
};
queue<pair<long long, long long>> enu(int n) {
  queue<pair<long long, long long>> q;
  for (int i = 0; i < n; i++) {
    for (int x = 0; x <= i; x++) {
      q.push({x, i - x});
    }
  }
  return q;
}
int main() {
  int n;
  cin >> n;
  vector<Infant> infants(n);
  for (int i = 0; i < (n); ++i) infants[i].index = i;
  for (int i = 0; i < (n); ++i) cin >> infants[i].active;
  sort(infants.rbegin(), infants.rend(),
       [&](Infant i, Infant j) { return i.active < j.active; });
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
  queue<pair<long long, long long>> q = enu(n);
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    long long i = p.first + p.second;
    Infant infant = infants[i];
    long long from = dp[p.first][p.second];
    long long to_l = abs(infant.index - p.first) * infant.active;
    long long to_r = abs(infant.index - (n - p.second - 1)) * infant.active;
    dp[p.first + 1][p.second] = max(dp[p.first + 1][p.second], from + to_l);
    dp[p.first][p.second + 1] = max(dp[p.first][p.second + 1], from + to_r);
  }
  vector<long long> candidate;
  for (int i = 0; i < (n); ++i) {
    long long now = *max_element(dp[i].begin(), dp[i].end());
    candidate.push_back(now);
  }
  long long ans = *max_element(candidate.begin(), candidate.end());
  cout << ans << endl;
}
