#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int e = 0, d, cont = 0;
long long int solve(long long int resp) {
  int ma, pos, aux;
  for (int i = 0; i < v.size() and e <= d; i++) {
    ma = 0;
    for (int j = 0; j < v.size(); j++) {
      if (ma < max(abs(j - e), abs(j - d)) * v[j]) {
        ma = max(abs(j - e), abs(j - d)) * v[j];
        pos = j;
      }
    }
    resp += ma;
    aux = pos;
    v[pos] = 0;
    if (abs(pos - e) == abs(pos - d)) {
      long long int op1, op2;
      e++;
      op2 = solve(resp);
      e--;
      d--;
      op1 = solve(resp);
      d--;
      v[pos] = aux;
      return max(op1, op2);
    } else if (abs(pos - e) > abs(pos - d)) {
      e++;
    } else
      d--;
  }
  return resp;
}
int main() {
  long long int n, ma, pos, resp;
  cin >> n;
  d = n - 1;
  for (int i = 0; i < n; i++) {
    cin >> ma;
    v.push_back(ma);
  }
  resp = solve(0);
  cout << resp << endl;
  return 0;
}
