#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
long mod = (long)1e9 + 7;
long ans[2001][2001] = {};
int main() {
  int n;
  cin >> n;
  vector<int> v(n, 0);
  set<P> s;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    s.emplace(P((-1 * x), i));
  }
  int x = 0;
  for (auto i : s) {
    ans[x + 1][0] = ans[x][0] + i.first * -1 * abs(i.second - x);
    ans[0][x + 1] = ans[0][x] + i.first * -1 * abs(i.second + x + 1 - n);
    for (int j = 0; j < (x); j++) {
      ans[x - j][1 + j] =
          max(ans[x - j - 1][1 + j] + i.first * -1 * abs(i.second - x + j + 1),
              ans[x - j][j] + i.first * -1 * abs(i.second + j + 1 - n));
    }
    x++;
  }
  long res = 0;
  for (int i = 0; i < (n + 1); i++) {
    res = max(res, ans[n - i][i]);
  }
  cout << res << "\n";
  return 0;
}
