#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<long long, long long>> v1, v2;
  vector<long long> point1(n, 0), point2(n, 0);
  for (int i = 0; i < n; i++) {
    v1.push_back({a[i], i});
    sort(v1.rbegin(), v1.rend());
    for (int j = 0; j < v1.size(); j++) {
      point1[i] += v1[j].first * abs(v1[j].second - (n - 1 - j));
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    v2.push_back({a[i], i});
    sort(v2.rbegin(), v2.rend());
    for (int j = 0; j < v2.size(); j++) {
      point2[i] += v2[j].first * abs(v2[j].second - j);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, point1[i] + point2[i + 1]);
  }
  cout << ans << endl;
  return 0;
}
