#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1e9 + 7;
signed main() {
  long long n, a[2000];
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    pair<long long, long long> a1[2000], a2[2000];
    for (long long j = 0; j < i; j++) a1[j] = make_pair(a[j], -j);
    for (long long j = 0; j < n - i; j++) a2[j] = make_pair(-a[j + i], -j - i);
    sort(a1, a1 + i);
    sort(a2, a2 + n - i);
    long long sum = 0;
    for (long long j = 0; j < i; j++)
      sum += a1[j].first * abs(n - i + j + a1[j].second);
    for (long long j = 0; j < n - i; j++)
      sum += -a2[j].first * abs(j + a2[j].second);
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
