#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[2022], b[2022];
void init(int lim) {
  for (int i = 1; i <= lim; i++) b[i] = a[n - i + 1];
  for (int i = lim + 1; i <= n; i++) b[i] = a[i - lim];
}
int cmp_asc(pair<int, int> &a, pair<int, int> &b) { return a < b; }
int cmp_desc(pair<int, int> &a, pair<int, int> &b) { return a > b; }
long long int calc() {
  long long int res = 0LL;
  for (int i = 1; i <= n; i++) res += 1LL * b[i].first * labs(b[i].second - i);
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  long long int ans = 0LL;
  for (int mid = 1; mid <= n; mid++) {
    init(mid);
    sort(b + 1, b + mid + 1, cmp_desc);
    sort(b + mid + 1, b + n + 1, cmp_asc);
    ans = max(ans, calc());
  }
  printf("%lld\n", ans);
  return 0;
}
