#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 5;
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
struct node {
  int id;
  long long val;
} arr[MAXN];
int vis[MAXN];
long long ans;
int n;
void dfs(int x, long long num) {
  if (x == n + 1) {
    ans = max(ans, num);
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (arr[x].id == i) continue;
    if (vis[i] == 0) {
      vis[i] = 1;
      dfs(x + 1, num + arr[x].val * abs(arr[x].id - i));
      vis[i] = 0;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i].val;
    arr[i].id = i;
  }
  ans = 0;
  dfs(1, 0);
  cout << ans << endl;
  return 0;
}
