#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % (long long)(1E9 + 7);
  if (c >= 0) return c;
  return c + (long long)(1E9 + 7);
}
long long inf = (long long)1E16;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long &pos, long long val) { pos = max(pos, val); }
void Min(long long &pos, long long val) { pos = min(pos, val); }
void Add(long long &pos, long long val) { pos = mod(pos + val); }
long double EPS = 1E-9;
long long a[2005];
bool c1(pair<long long, long long> x, pair<long long, long long> y) {
  return x.second < y.second;
}
bool c2(pair<long long, long long> x, pair<long long, long long> y) {
  return x.second > y.second;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i <= n - 1; i++) cin >> a[i];
  long long ans = 0;
  for (long long z = 0; z <= n - 1; z++) {
    vector<pair<long long, long long> > b;
    long long t = n - 1 - z;
    for (long long i = 0; i <= z; i++) {
      b.push_back({t, a[i]});
      t++;
    }
    t = 0;
    for (long long i = z + 1; i <= n - 1; i++) {
      b.push_back({t, a[i]});
      t++;
    }
    sort(b.begin(), b.begin() + z + 1, c1);
    sort(b.begin() + z + 1, b.begin() + n, c2);
    long long sum = 0;
    for (long long i = 0; i <= n - 1; i++) {
      sum += a[i] * abs(i - b[i].first);
    }
    Max(ans, sum);
  }
  cout << ans << "\n";
  return 0;
}
