#include <bits/stdc++.h>
using Int = long long;
struct SetupIO {
  SetupIO() {
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
        std::cout << std::fixed << std::setprecision(13);
  }
} setup_io;
template <class T>
inline bool chmin(T& a, const T& b) {
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T>
inline bool chmax(T& a, const T& b) {
  if (a >= b) return false;
  a = b;
  return true;
}
signed main() {
  Int n;
  std::cin >> n;
  std::vector<Int> a(n);
  for (Int i = (0), limi = (n); i < limi; i++) std::cin >> a[i];
  Int ma = -1;
  for (Int k = (0), limk = (n); k < limk; k++) {
    std::vector<Int> ord(n);
    std::iota(ord.begin(), ord.end(), 0);
    std::sort(ord.begin(), ord.begin() + k,
              [&](Int i, Int j) { return a[i] < a[j]; });
    std::sort(ord.begin() + k, ord.end(),
              [&](Int i, Int j) { return a[i] < a[j]; });
    Int acc = 0;
    for (Int i = (0), limi = (k); i < limi; i++) {
      acc += std::abs((n - k + i) - ord[i]) * a[ord[i]];
    }
    for (Int i = (k), limi = (n); i < limi; i++) {
      acc += std::abs((n - 1 - i) - ord[i]) * a[ord[i]];
    }
    chmax(ma, acc);
  }
  std::cout << ma << std::endl;
}
