#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long int powD(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % (long long int)(1e9 + 7);
    x = (x * x) % (long long int)(1e9 + 7);
    y = y >> 1;
  }
  return res;
}
vector<long long int> a(2000);
int n;
long long int first(long long int l, long long int r, set<long long int> st) {
  long long int Al = -1, Ar = -1;
  long long int rdx, ldx;
  if (l == r) {
    long long int i = *st.begin();
    return a[i] * abs(i - l);
  }
  set<long long int> sr(st), sl(st);
  for (auto i : st) {
    if (a[i] * abs(l - i) > Al) {
      Al = a[i] * abs(l - i);
      ldx = i;
    }
    if (a[i] * abs(r - i) > Ar) {
      Ar = a[i] * abs(r - i);
      rdx = i;
    }
  }
  long long int ans;
  sr.erase(rdx);
  sl.erase(ldx);
  ans = Al + first(l + 1, r, sl);
  ans = max(ans, Ar + first(l, r - 1, sr));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  set<long long int> second;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    second.insert(i);
  }
  cout << first(0, n - 1, second) << "\n";
}
