#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

void setmax(ll& a, ll b) {
  if (a < b) a = b;
}

int main() {
  in(int, n);
  vector<pair<int, int>> ai(n);
  rep(i, n) {
    cin >> ai[i].first;
    ai[i].second = i;
  }
  sort(all(ai), greater());
  vector<vector<ll>> dp(n + 1, vector(n + 1, 0LL));
  rep(i, n) rep(j, i + 1) {
    auto [a, index] = ai[i];
    setmax(dp[i + 1][j + 1], dp[i][j] + a * abs(index - j));
    setmax(dp[i + 1][j], dp[i][j] + a * abs(index - (n - 1 - (i - j))));
    // dbg(a, index, j, dp[i][j], dp[i + 1][j + 1], dp[i + 1][j]);
  }
  ll ans = 0;
  rep(i, n + 1) setmax(ans, dp[n][i]);
  out(ans);
}
