#include <bits/stdc++.h>
using namespace std;
long long int dp[2001][2001] = {};
unordered_map<string, long long int> m;
long long int arr[2001] = {};
long long int helper(long long int i, long long int n, string s) {
  if (i > n) return 0;
  if (m.count(s) > 0) return m[s];
  long long int ans = 0;
  for (long long int j = 0; j < n; j++) {
    if (s[j] == '0') {
      string s1 = s;
      s1[j] = '1';
      ans = max(ans, dp[i][j] + helper(i + 1, n, s1));
    }
  }
  m[s] = ans;
  return ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    m.clear();
    long long int n;
    cin >> n;
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < n; j++) {
        dp[i][j] = arr[i] * (abs(j - i));
      }
    }
    string s;
    for (long long int i = 0; i < n; i++) s += '0';
    long long int ans = helper(0, n, s);
    cout << ans << endl;
  }
}
