#include <bits/stdc++.h>
const int maxn = 2005;
int n, head, tail;
long long ans, a[maxn];
bool vis[maxn];
long long DFS(int head, int tail) {
  if (head > tail) return 0;
  long long maxx = -1, maxn;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i] &&
        maxx < a[i] * std::max(std::abs(i - head), std::abs(i - tail))) {
      maxx = a[i] * std::max(std::abs(i - head), std::abs(i - tail));
      maxn = i;
    }
  }
  vis[maxn] = 1;
  if (std::abs(maxn - head) < std::abs(maxn - tail))
    maxx += DFS(head, tail - 1);
  else if (std::abs(maxn - head) > std::abs(maxn - tail))
    maxx += DFS(head + 1, tail);
  else
    maxx += std::max(DFS(head, tail - 1), DFS(head + 1, tail));
  vis[maxn] = 0;
  return maxx;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  printf("%lld", DFS(1, n));
}
