#include <bits/stdc++.h>
using namespace std;
struct node {
  int id;
  long long val;
  bool operator<(const node& n) const { return val < n.val; }
} a[2005], b[2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i].id = i;
    cin >> a[i].val;
    b[i].id = i;
    b[i].val = a[i].val;
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i != 0) sort(a + 1, a + 1 + i);
    if (i != n) sort(a + 1 + i, a + 1 + n);
    long long temp = 0;
    for (int j = i; j >= 1; j--) {
      long long locate = n - (i - j);
      temp += abs(locate - a[j].id) * a[j].val;
    }
    for (int j = n; j > i; j--) {
      long long locate = 1 + n - j;
      temp += abs(locate - a[j].id) * a[j].val;
    }
    long long temp2 = 0;
    for (int j = i; j >= 1; j--) {
      long long locate = 1 + (i - j);
      temp2 += abs(locate - a[j].id) * a[j].val;
    }
    for (int j = n; j > i; j--) {
      long long locate = n - (n - j);
      temp2 += abs(locate - a[j].id) * a[j].val;
    }
    ans = max(ans, temp);
    ans = max(ans, temp2);
    for (int j = 1; j <= n; j++) {
      a[j].id = b[j].id;
      a[j].val = b[j].val;
    }
  }
  cout << ans << '\n';
  return 0;
}
