#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
template <class T>
inline bool UpdateMin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool UpdateMax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  int64 ans = 0;
  for (int k = 1; k <= n - 1; k++) {
    int64 score = 0;
    vector<pair<int64, int>> pairs;
    for (int i = 0; i < k; i++) {
      pairs.push_back({xs[i], i});
    }
    sort(pairs.begin(), pairs.end());
    reverse(pairs.begin(), pairs.end());
    for (int i = 0; i < k; i++) {
      auto [w, index] = pairs[i];
      score += w * ((n - 1 - i) - index);
    }
    pairs.clear();
    for (int i = k; i < n; i++) {
      pairs.push_back({xs[i], i});
    }
    sort(pairs.begin(), pairs.end());
    reverse(pairs.begin(), pairs.end());
    for (int i = 0; i < n - k; i++) {
      auto [w, index] = pairs[i];
      score += w * (index - i);
    }
    UpdateMax(ans, score);
  }
  cout << ans << endl;
}
