#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
const long long MOD = 1000000007;
long long n;
signed main() {
  cin >> n;
  vector<pair<long long, long long> > a(n + 1);
  a[0].first = -1;
  a[0].second = -1;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  long long res = 0;
  long long ans = 0;
  sort(a.begin(), a.end());
  vector<bool> memo(n + 1, true);
  long long left = 1;
  long long right = n;
  queue<pair<long long, long long> > buf;
  vector<pair<long long, long long> > b(a);
  for (long long j = 0; j < n; ++j) {
    long long tmp = 0;
    a = b;
    left = 1;
    right = n;
    res = 0;
    for (long long i = n; i > 0; i--) {
      if (a[i].second > j) continue;
      if (abs(right - a[i].second) >= abs(a[i].second - left)) {
        res += abs(right - a[i].second) * a[i].first;
        right--;
        a[i].first = inf;
      }
    }
    for (long long i = n; i > 0; i--) {
      if (a[i].first == inf) continue;
      if (abs(right - a[i].second) == abs(a[i].second - left)) {
        buf.push(a[i]);
        continue;
      } else if (abs(right - a[i].second) > abs(a[i].second - left)) {
        res += abs(right - a[i].second) * a[i].first;
        right--;
        if (!buf.empty()) {
          res += abs(left - buf.front().second) * buf.front().first;
          buf.pop();
          left++;
        }
      } else {
        res += abs(left - a[i].second) * a[i].first;
        left++;
        if (!buf.empty()) {
          res += abs(right - buf.front().second) * buf.front().first;
          buf.pop();
          right--;
        }
      }
    }
    buf.pop();
    if (a[1].first != inf) res += abs(left - a[1].second) * a[1].first;
    ans = max(res, ans);
  }
  cout << ans << "\n";
  return 0;
}
