#include <bits/stdc++.h>
using namespace std;
const int MD = (int)1e9 + 7;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2>
void dbg(const T& fst, const T2&... rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2>
void amax(T& a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  vector<vector<long long> > dp(n + 1, vector<long long>(n + 1));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) {
      if (i + j == n) {
        ans = max(ans, dp[i][j]);
        break;
      }
      amax(dp[i + 1][j], dp[i][j] + abs(a[i + j].second - i) * a[i + j].first);
      amax(dp[i][j + 1],
           dp[i][j] + abs(a[i + j].second - (n - 1 - j)) * a[i + j].first);
    }
  cout << ans << "\n";
  return 0;
}
