#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (int i = 0; i < ((int)v.size()); ++i) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
template <typename T, size_t S>
void printArray(const T (&array)[S]) {
  for (auto val : array) std::cout << val << ", ";
  std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);
  int n;
  std::cin >> n;
  vector<pi> a;
  for (int i = 0; i < (n); ++i) {
    int ai;
    std::cin >> ai;
    a.push_back({ai, i + 1});
  }
  sort(a.rbegin(), a.rend());
  vvl dp(n + 1, vl(n + 1));
  for (int i = 1; i <= (n); ++i) {
    for (int j = 0; j < (i); ++j) {
      (dp[i][j + 1] =
           max(dp[i][j + 1],
               dp[i - 1][j] + a[i - 1].first * abs(a[i - 1].second - (j + 1))));
      (dp[i][j] = max(
           dp[i][j], dp[i - 1][j] + a[i - 1].first * abs(a[i - 1].second -
                                                         (n - ((i - 1) - j)))));
    }
  }
  ll ans = 0;
  for (int i = 0; i < (n); ++i) (ans = max(ans, dp[n][i]));
  std::cout << ans << "\n";
}
