#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long ac[n];
  priority_queue<pair<pair<long long, long long>, pair<int, int>>> happy;
  int mae[n], ato[n];
  long long Ans = 0;
  for (int i1 = 0; i1 < n; ++i1) {
    cin >> ac[i1];
  }
  for (int l = 0; l < 100; ++l) {
    priority_queue<pair<pair<long long, long long>, pair<int, int>>>().swap(
        happy);
    for (int k = 0; k < n; ++k) {
      mae[k] = 0;
      ato[k] = 0;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        pair<int, int> t = make_pair(0, 0);
        pair<long long, long long> s = make_pair(0, 0);
        pair<pair<long long, long long>, pair<int, int>> tmp = make_pair(s, t);
        tmp.first.first = ac[i] * abs(j - i);
        tmp.first.second = rand();
        tmp.second.first = i;
        tmp.second.second = j;
        happy.push(tmp);
      }
    }
    int now = 0;
    long long ans = 0;
    while (now < n) {
      pair<pair<long long, long long>, pair<int, int>> m = happy.top();
      happy.pop();
      if (mae[m.second.first] == 0 && ato[m.second.second] == 0) {
        ans += m.first.first;
        mae[m.second.first] = 1;
        ato[m.second.second] = 1;
        now++;
      }
    }
    Ans = max(ans, Ans);
  }
  cout << Ans << endl;
  return 0;
}
