#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;
  int left{0}, right{n - 1};
  long long int score{0};
  for (auto i = 0; i < n; ++i) {
    int max{0};
    long long int max_score{-1};
    for (auto j = 0; j < n; ++j) {
      if (activity[j] > 0) {
        const auto left_score = std::abs(j - left) * activity[j];
        const auto right_score = std::abs(j - right) * activity[j];
        if (max_score < std::max(left_score, right_score)) {
          max_score = std::max(left_score, right_score);
          max = j;
        }
      }
    }
    const auto left_score = std::abs(max - left) * activity[max];
    const auto right_score = std::abs(max - right) * activity[max];
    if (left_score > right_score) {
      score += left_score;
      ++left;
    } else {
      score += right_score;
      --right;
    }
    activity[max] = 0;
  }
  std::cout << score << std::endl;
}
