#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n;
pair<long long, long long> a[N];
long long ans, f[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[i] = make_pair(x, i);
  }
  sort(a + 1, a + n + 1, greater<pair<long long, long long> >());
  for (int i = 1; i <= n; i++) {
    int x = a[i].first, y = a[i].second;
    for (int j = 0; j < i; j++)
      f[j][i - j] = max(f[j - 1][i - j] + x * (y - j + 1),
                        f[j][i - j - 1] + x * (n - (i - j) - y));
  }
  for (int i = 1; i <= n; i++) ans = max(ans, f[i][n - i]);
  printf("%lld\n", ans);
  return 0;
}
