#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  set<long long> st, st1;
  for (long long i = 0; i < (long long)n; ++i) {
    cin >> a[i].first;
    a[i].second = i + 1;
    st.insert(i + 1);
  }
  st1 = st;
  sort(a.rbegin(), a.rend());
  long long res = 0, ans = 0;
  for (long long j = 0; j < (long long)n; ++j) {
    st = st1;
    res = 0;
    long long left = *st.begin();
    long long right = *st.rbegin();
    if (abs(a[j].second - left) < abs(a[j].second - right)) {
      res += a[j].first * (abs(a[j].second - right));
      st.erase(st.find(right));
    } else {
      res += a[j].first * (abs(a[j].second - left));
      st.erase(st.find(left));
    }
    for (long long i = 0; i < (long long)n; ++i) {
      if (i == j) continue;
      long long left = *st.begin();
      long long right = *st.rbegin();
      if (abs(a[i].second - left) < abs(a[i].second - right)) {
        res += a[i].first * (abs(a[i].second - right));
        st.erase(st.find(right));
      } else {
        res += a[i].first * (abs(a[i].second - left));
        st.erase(st.find(left));
      }
    }
    ans = max(ans, res);
  }
  cout << ans;
  return 0;
}
