#include <bits/stdc++.h>
using namespace std;
set<int> visited;
int N;
int dfs(int st, int ip[]) {
  if (st >= N) return 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (visited.find(i) == visited.end() && i != st) {
      visited.insert(i);
      ans = max(ans, ip[st] * abs(i - st) + dfs(st + 1, ip));
      visited.erase(i);
    }
  }
  return ans;
}
int main() {
  cin >> N;
  int ip[N];
  for (int i = 0; i < N; i++) {
    cin >> ip[i];
  }
  cout << dfs(0, ip);
  return 0;
}
