#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<pair<int, int>> v;
  for (int i = 0; i < N; i++) v.emplace_back(A[i], i);
  long long ans;
  for (int i = 0; i <= N; i++) {
    vector<pair<int, int>> v3(v.begin(), v.begin() + i);
    vector<pair<int, int>> v2(v.begin() + i, v.end());
    sort(v2.begin(), v2.end());
    sort(v3.begin(), v3.end());
    reverse(v2.begin(), v2.end());
    v2.insert(v2.end(), v3.begin(), v3.end());
    long long ans1 = 0;
    for (int j = 0; j < N; j++) {
      ans1 += v2[j].first * 1LL * abs(v2[j].second - j);
    }
    ans = max(ans, ans1);
  }
  cout << ans << endl;
  return 0;
}
