#include <bits/stdc++.h>
using namespace std;
long long maxFrom(int currIndex, bitset<2000> path,
                  const vector<long long>& A) {
  int N = A.size();
  if (currIndex == N - 1) {
    for (int i = 0; i < N; ++i) {
      if (!path.test(i)) {
        return A[currIndex] * abs(currIndex - i);
      }
    }
  }
  long long currMax = -1LL;
  bitset<2000> currPath = path;
  for (int i = 0; i < N; ++i) {
    if (path.test(i)) {
      continue;
    }
    bitset<2000> tempPath = path;
    tempPath.set(i);
    long long tempMax =
        maxFrom(currIndex + 1, tempPath, A) + A[currIndex] * abs(currIndex - i);
    if (currMax < 0 || currMax < tempMax) {
      currMax = tempMax;
      currPath = tempPath;
    }
  }
  return currMax;
}
int main() {
  int N;
  cin >> N;
  vector<long long> A(N, 0LL);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  bitset<2000> path(0);
  long long ans = maxFrom(0, path, A);
  cout << ans << endl;
  return 0;
}
