#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n;
pair<long long, long long> a[N];
long long 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);
  for (int i = 1; i <= n; i++) f[i][i] = a[1].first * abs(a[1].second - i);
  for (int k = 2; k <= n; k++) {
    int x = a[k].first, y = a[k].second;
    for (int i = 1, j = k; j <= n; i++, j++)
      f[i][j] = max(f[i][j - 1] + x * abs(y - j), f[i + 1][j] + x * abs(y - i));
  }
  printf("%lld\n", f[1][n]);
  return 0;
}
