#include <bits/stdc++.h>
using namespace std;
long long Abs(long long x) {
  if (x > 0)
    return x;
  else
    return (-x);
}
int main(void) {
  long long N, L, R, a, x, y, A[2005], i;
  int l, r;
  l = 0;
  r = 0;
  scanf("%lld", &N);
  vector<pair<int, int> > P(N);
  for (i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    P[i] = make_pair(A[i], i);
  }
  std::sort(P.begin(), P.end());
  x = 0;
  L = -1;
  R = N;
  for (i = N - 1; i >= 0; i--) {
    if (abs((L + 1) - P[i].second) > abs((R - 1) - P[i].second)) {
      a = L + 1;
      L++;
      if (i == N - 1) l = 1;
    } else {
      a = R - 1;
      R--;
      if (i == N - 1) r = 1;
    }
    x += P[i].first * Abs(a - P[i].second);
  }
  y = 0;
  L = -1;
  R = N;
  for (i = N - 1; i >= 0; i--) {
    if (abs((L + 1) - P[i].second) > abs((R - 1) - P[i].second) && i != N - 1 ||
        r == 1 && i == N - 1) {
      a = L + 1;
      L++;
    } else {
      a = R - 1;
      R--;
    }
    y += P[i].first * Abs(a - P[i].second);
  }
  if (y > x) x = y;
  printf("%lld", x);
  return 0;
}
