#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
namespace {
template <typename T>
void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <typename T>
void chmin(T& a, T b) {
  a = std::min(a, b);
}
template <typename T>
void chadd(T& a, T b) {
  a = a + b;
}
void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
template <typename T>
void Cout(const T& x, const char* end = "\n") {
  std::cout << x << end;
}
template <typename T>
void Cout(const std::vector<T>& x, const char* sep = " ",
          const char* end = "\n") {
  for (std::size_t i = 0, sz = x.size(); i < sz; i++) {
    std::cout << x[i] << (i == sz - 1 ? end : sep);
  }
}
struct inp {
  std::size_t sz;
  inp(std::size_t _sz = 1) : sz(_sz) {}
  template <typename T>
  operator T() const {
    T a;
    std::cin >> a;
    return a;
  }
  template <typename T>
  operator std::vector<T>() const {
    vector<T> a(sz);
    for (std::size_t i = 0; i < sz; i++) std::cin >> a[i];
    return a;
  }
  template <typename T, typename U>
  operator std::pair<T, U>() const {
    T f;
    U s;
    std::cin >> f >> s;
    return std::pair<T, U>(f, s);
  }
};
inp inp1;
struct Child {
  ll value;
  int prev;
};
}  // namespace
int main() {
  int n = inp1;
  vector<ll> a = inp(n);
  vector<Child> childs(n);
  for (ll i = 0; i < n; ++i) {
    childs[i].value = a[i];
    childs[i].prev = i;
  }
  sort((childs).begin(), (childs).end(),
       [](Child& lhs, Child& rhs) { return lhs.value > rhs.value; });
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0LL));
  for (ll i = 0; i < n; ++i) {
    for (ll j = 0; j < i + 1; ++j) {
      int right = i - j;
      chmax(dp[i + 1][j + 1],
            dp[i][j] + childs[i].value * abs(childs[i].prev - j));
      chmax(dp[i + 1][j],
            dp[i][j] + childs[i].value * abs(childs[i].prev - (n - right - 1)));
    }
  }
  ll ans = 0LL;
  for (ll i = 0; i < n + 1; ++i) {
    chmax(ans, dp[n][i]);
  }
  Cout(ans);
  return 0;
}
