#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
priority_queue<long long, vector<long long>, greater<long long> > pq1;
long long result(long long a, long long b, long long p) {
  long long ans = 1;
  if (b == (-1)) b = p - 2;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % p;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return ans;
}
long long T, n, m;
vector<vector<long long> > dp(2000, vector<long long>(2000, 0));
long long solve(long long i, vector<long long> vis) {
  if (i == n) return 0;
  long long ans = 0;
  for (int j = 0; j < n; j++) {
    if (!vis[j]) {
      vis[j]++;
      ans = max(ans, dp[i][j] + solve(i + 1, vis));
      vis[j]--;
    }
  }
  return ans;
}
int main() {
  if (fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = a[i] * (abs(i - j));
    }
  }
  vector<long long> vis(n, 0);
  cout << solve(0, vis);
  return 0;
}
