#include <bits/stdc++.h>
using namespace std;
int n;
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (b.first > a.first) return true;
  return false;
}
void solve() {
  cin >> n;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) {
    int f;
    cin >> f;
    p[i] = make_pair(f, i);
  }
  long long dp[2020];
  dp[0] = 0;
  for (int k = 0; k < n; k++) {
    dp[k + 1] = dp[k] + (long long)p[k].first * (p[k].second - k);
    for (int i = k - 1, j = 0; i >= 0; i--, j++) {
      dp[i + 1] =
          max(dp[i] + (long long)p[k].first * (p[k].second - i),
              dp[i + 1] + (long long)p[k].first * (n - 1 - j - p[k].second));
    }
    dp[0] += (long long)(p[k].first) * (n - 1 - k - p[k].second);
  }
  cout << *max_element(dp, dp + n + 1) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
