#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int a[maxn];
bool take[maxn];
long long ans, sum;
int n;
void dfs(int u, int k) {
  if (k == 0) {
    ans = max(sum, ans);
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (!take[i]) {
      take[i] = true;
      sum += 1ll * abs(u - i) * a[u];
      dfs(u + 1, k - 1);
      sum -= 1ll * abs(u - i) * a[u];
      take[i] = false;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dfs(1, n);
  cout << ans << '\n';
}
