#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <class T>
using vv = vector<vector<T>>;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) os << (i ? ", " : "") << vec[i];
  os << "}";
  return os;
}
ostream& operator<<(ostream& os, const vector<char>& v) {
  for (size_t i = 0; i < v.size(); ++i) os << v[i];
  return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& rhs) {
  os << "(" << rhs.first << ", " << rhs.second << ")";
  return os;
}
int main() {
  int N;
  cin >> N;
  ;
  priority_queue<pii> q;
  for (int i = 0, _i = (N); i < _i; ++i) {
    int a;
    cin >> a;
    ;
    q.emplace(a, i);
  }
  vv<ll> dp(N + 1, vector<ll>(N + 1));
  for (int i = 0, _i = (N); i < _i; ++i) {
    auto [a, idx] = q.top();
    q.pop();
    for (int j = 0, _i = (i + 1); j < _i; ++j) {
      chmax(dp[i + 1][j], dp[i][j] + a * abs(N - (i - j) - 1 - idx));
      chmax(dp[i + 1][j + 1], dp[i][j] + abs(idx - j) * a);
    }
  }
  cout << *(([&](decltype((dp[N])) cccc) {
    return (max_element)(begin(cccc), end(cccc));
  })(dp[N]))
       << endl;
  return 0;
}
