#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
using ll = long long;
using P = pair<long long, long long>;
vector<P> res;
long long dp[2200][2200];
long long n;
long long dfs(long long l, long long r) {
  if (l == 0 && r == 0) return 0;
  if (l < 0 || r < 0) return -1001001001;
  if (dp[l][r] != -1) return dp[l][r];
  long long ret = 0;
  auto now = res[l + r - 1];
  ret = max(ret, dfs(l, r - 1) + now.first * abs(now.second - (n - r)));
  ret = max(ret, dfs(l - 1, r) + now.first * abs(now.second - (l - 1)));
  return dp[l][r] = ret;
}
signed main() {
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (2200); i++)
    for (long long j = 0; j < (2200); j++) dp[i][j] = -1;
  for (long long i = 0; i < (n); i++) {
    cin >> a[i];
    res.emplace_back(a[i], i);
  }
  sort(res.rbegin(), res.rend());
  long long ret = 0;
  for (long long i = 0; i < (n + 1); i++) {
    ret = max(ret, dfs(i, n - i));
  }
  cout << ret << endl;
  return 0;
}
