#include <bits/stdc++.h>
using namespace std;
const double h = 1e-6;
const int MAX_ = 200005;
inline long long int mul(long long int a, long long int b) {
  return (a * 1ll * b) % 1000000007;
}
inline long long int sub(long long int a, long long int b) {
  long long int c = a - b;
  if (c < 0) c += 1000000007;
  return c;
}
inline long long int add(long long int a, long long int b) {
  long long int c = a + b;
  if (c > 1000000007) c -= 1000000007;
  return c;
}
long long int sqr(long long int x) { return x * x; }
const int nax = 2005;
int n;
pair<int, int> arr[nax];
int dp[nax][nax];
int get_ac(int cur, int l, int r) {
  if (cur >= n) return 0;
  if (dp[cur][l] != -1) return dp[cur][l];
  int left =
      arr[cur].first * abs(l - arr[cur].second) + get_ac(cur + 1, l + 1, r);
  int right =
      arr[cur].first * abs(r - arr[cur].second) + get_ac(cur + 1, l, r - 1);
  dp[cur][l] = max(left, right);
  return dp[cur][l];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (long long int i = 0; i < n; i++) {
    int val;
    cin >> val;
    arr[i].first = val;
    arr[i].second = i;
  }
  sort(arr, arr + n);
  reverse(arr, arr + n);
  cout << get_ac(0, 0, n - 1);
  return 0;
}
