#include <bits/stdc++.h>
using namespace std;
const long long int N = 300005;
void cs(long long int &x) { cout << "Case #" << x << ": "; }
bool cmp(string a, string b) { return a + b < b + a; }
long long int dp[2002];
long long int help(long long int i, long long int n, vector<long long int> &v,
                   vector<long long int> &vis) {
  if (i == n)
    return 0;
  else {
    long long int d = 0;
    for (long long int j = 0; j < n; j++) {
      if (i == j) continue;
      if (vis[j] == 0) {
        vis[j] = 1;
        d = max(d, v[i] * (abs(i - j)) + help(i + 1, n, v, vis));
        vis[j] = 0;
      }
    }
    return d;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  for (long long int i = 0; i < 2002; i++) dp[i] = -1;
  vector<long long int> vis(n, 0), v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  long long int ans = help(0, n, v, vis);
  cout << ans << "\n";
  return 0;
}
