#include <bits/stdc++.h>
using namespace std;
void perm(int*, int, void (*)(int*));
void rotate(int*, int, int);
void copy(int*, int*);
void print(int*);
int N, A[2000], I[2000], tmp = 0, Mx = 0;
void perm(int* num, int i, void (*take)(int*)) {
  if (i < N) {
    int j;
    for (j = i; j < N; j++) {
      int to[N];
      copy(num, to);
      rotate(to, i, j);
      perm(to, i + 1, take);
    }
  } else {
    take(num);
  }
}
void rotate(int* num, int i, int j) {
  int tmp = num[j];
  int k;
  for (k = j; k > i; k--) {
    num[k] = num[k - 1];
  }
  num[i] = tmp;
}
void copy(int* from, int* to) {
  int i;
  for (i = 0; i < N; i++) {
    to[i] = from[i];
  }
}
void cal(int* num) {
  int i;
  tmp = 0;
  for (i = 0; i < N; i++) {
    tmp += (A[i] * abs((i + 1) - num[i]));
  }
  Mx = tmp > Mx ? tmp : Mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) I[i] = i + 1;
  perm(I, 0, cal);
  cout << Mx << '\n';
  return 0;
}
