#include <inttypes.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
 
const int MAXN = 2000;
 
int a[MAXN];
 
int64_t calc(int mid, int n) {
  std::vector<std::pair<int, int>> vec;
  for (int i = 0; i < n; ++i) {
    vec.emplace_back(a[i], i);
  }
  auto mid_iter = vec.begin() + mid;
  std::sort(vec.begin(), mid_iter);
  std::sort(mid_iter, vec.end(), [](const auto& x, const auto& y) {
    return x > y; 
  });
 
  int64_t sum = 0;
  for (int i = 0; i < vec.size(); ++i) {
    if (i < mid) 
      sum += (int64_t)vec[i].first * std::abs(n - mid + i - vec[i].second);
    else 
      sum += (int64_t)vec[i].first * std::abs(vec[i].second - i + mid);
  }
  return sum;
}
 
int64_t solve(int n) {
  int64_t sum = 0;
  for (int mid = 0; mid <= n; ++mid) {
    int64_t cur_sum = calc(mid, n);
    if (cur_sum > sum) sum = cur_sum;
  }
  return sum;
}
 
int main() {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  std::cout << solve(n) << std::endl;
  return 0;
}