#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    vector<pair<long long, int> > left, right;
    for (int j = 0; j < i; j++) left.push_back({a[j], j});
    for (int j = i; j < n; j++) right.push_back({a[j], j});
    sort(left.begin(), left.end(), greater<pair<long long, int> >());
    sort(right.begin(), right.end(), greater<pair<long long, int> >());
    long long ret = 0;
    for (int j = 0; j < left.size(); j++) {
      long long val = left[j].first;
      int idx = left[j].second;
      ret += val * abs(n - 1 - j - idx);
    }
    for (int j = 0; j < right.size(); j++) {
      long long val = right[j].first;
      int idx = right[j].second;
      ret += val * abs(j - idx);
    }
    ans = max(ans, ret);
  }
  cout << ans << "\n";
  return 0;
}
