#include <bits/stdc++.h>
using namespace std;
void read(int &x) { scanf("%d", &x); }
void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int n;
pair<int, int> a[2003];
bool cmp(pair<int, int> A, pair<int, int> B) { return A.first > B.first; }
long long dp[2003][2003], ans;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i].first), a[i].second = i;
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 0; i <= n; i++)
    for (int j = 0; i + j <= n; j++) {
      if (i > 0)
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1ll * abs(a[i + j].second - i) *
                                                    a[i + j].first);
      if (j > 0)
        dp[i][j] = max(dp[i][j],
                       dp[i][j - 1] + 1ll * abs(n - j + 1 - a[i + j].second) *
                                          a[i + j].first);
    }
  for (int i = 0; i <= n; i++) ans = max(ans, dp[i][n - i]);
  write(ans);
}
