#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < int(n); i++) cin >> a[i];
  ll ans = 0;
  for (int j = 0; j < int(n + 1); j++) {
    ll sum = 0;
    vector<pair<ll, int>> l, r;
    for (int i = 0; i < int(j); i++) l.push_back({a[i], i});
    for (int i = j; i < n; i++) r.push_back({a[i], i});
    sort(l.begin(), l.end());
    sort(r.rbegin(), r.rend());
    vector<pair<ll, int>> res = r;
    for (int i = 0; i < int(l.size()); i++) res.push_back(l[i]);
    for (int i = 0; i < int(n); i++)
      sum += res[i].first * (abs(res[i].second - i));
    chmax(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
