#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<long long int> activity(n);
  for (auto& a : activity) std::cin >> a;
  std::vector<int> left, right;
  left.reserve(n);
  right.reserve(n);
  long long int max_score = 0;
  for (auto mid = 0; mid <= n; ++mid) {
    left.resize(mid);
    right.resize(n - mid);
    std::iota(left.begin(), left.end(), 0);
    std::iota(right.begin(), right.end(), mid);
    std::sort(left.begin(), left.end(), [&activity](int a, int b) {
      return (activity[a] == activity[b]) ? a < b : activity[a] < activity[b];
    });
    std::sort(right.begin(), right.end(), [&activity](int a, int b) {
      return (activity[a] == activity[b]) ? a < b : activity[a] > activity[b];
    });
    long long int score = 0;
    for (auto i = 0; i < left.size(); ++i) {
      const auto a = activity[left[i]];
      score += a * std::abs(n - mid + i - left[i]);
    }
    for (auto i = 0; i < right.size(); ++i) {
      const auto a = activity[right[i]];
      score += a * std::abs(i - right[i]);
    }
    max_score = std::max(max_score, score);
  }
  std::cout << max_score << std::endl;
}
