#include <bits/stdc++.h>
using namespace std;
void testCase() {}
long long A[10000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  long long best = 0;
  for (int i = 0; i <= n; i++) {
    vector<pair<long long, int>> ekat;
    vector<pair<long long, int>> tokat;
    for (int j = 1; j <= i; j++) {
      ekat.push_back({A[j], j});
    }
    for (int j = i + 1; j <= n; j++) {
      tokat.push_back({A[j], j});
    }
    sort(ekat.rbegin(), ekat.rend());
    sort(tokat.rbegin(), tokat.rend());
    long long sum = 0;
    int left = 1;
    for (auto p : tokat) {
      sum += p.first * abs(p.second - left);
      left++;
    }
    int right = n;
    for (auto p : ekat) {
      sum += p.first * abs(p.second - right);
      right--;
    }
    best = max(best, sum);
  }
  cout << best << "\n";
}
