#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7;
const int mod = 1e9 + 7;
int n;
long long a[N];
int parent[2][N];
vector<pair<long long, pair<int, int> > > bst;
int getP(int id, int u) {
  if (u == parent[id][u]) {
    return u;
  }
  return parent[id][u] = getP(id, parent[id][u]);
}
void join(int id, int u, int v) {
  u = getP(id, u);
  v = getP(id, v);
  parent[id][v] = u;
}
bool cmp(pair<long long, pair<int, int> > a,
         pair<long long, pair<int, int> > b) {
  if (a.first > b.first) return 1;
  if (a.first == b.first) {
    if (a.second.first < b.second.first) return 1;
  }
  return 0;
}
long long ans = 0;
void tryy() {
  for (int i = 1; i < N; i++) {
    parent[0][i] = i;
    parent[1][i] = i;
  }
  long long tmp = 0;
  for (auto V : bst) {
    int u = V.second.first;
    int v = V.second.second;
    long long cost = V.first;
    if (getP(0, u) != getP(0, n + 1) && getP(1, v) != getP(1, n + 1)) {
      tmp += cost;
      join(0, u, n + 1);
      join(1, v, n + 1);
    }
  }
  ans = max(ans, tmp);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < N; i++) {
    parent[0][i] = i;
    parent[1][i] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      bst.push_back({a[i] * abs(i - j), {i, j}});
    }
  }
  sort(bst.begin(), bst.end(), cmp);
  tryy();
  sort(bst.rbegin(), bst.rend());
  tryy();
  printf("%lld\n", ans);
}
