#include <bits/stdc++.h>
using namespace std;
const long long N = 2010;
long long a[N], n, b[N], ans;
long long dp[N][N];
long long m[N], vis[N];
bool cmp(long long a, long long b) { return a > b; }
int main() {
  freopen("in.txt", "r", stdin);
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1, cmp);
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      if (b[i] == a[j] && !vis[j]) {
        vis[j] = 1;
        m[i] = j;
        break;
      }
    }
  }
  for (long long s = 1; s <= n; ++s) {
    dp[s][0] = dp[s - 1][0] + b[s] * (m[s] - s);
    dp[0][s] = dp[0][s - 1] + b[s] * (n + 1 - s - m[s]);
    for (long long x = 1, y = s - 1; x < s; ++x, --y) {
      dp[x][y] = max(dp[x][y - 1] + b[s] * (n + 1 - y - m[s]),
                     dp[x - 1][y] + b[s] * (m[s] - x));
    }
  }
  for (long long i = 0; i <= n; ++i) {
    if (ans < dp[i][n - i]) ans = dp[i][n - i];
  }
  printf("%lld", ans);
}
