#include <algorithm>
#include <array>
#include <iostream>
#include <utility>

int main()
{
    int n;
    std::cin >> n;

    constexpr int size                          = 2001;
    std::array<std::pair<int, int>, size> score = {std::make_pair(0, 0)};
    for (int i = 0; i < n; ++i)
    {
        std::cin >> score[i].first;
        score[i].second = i;
    }
    std::sort(score.begin(), score.end(), [](auto const& lhs, auto const& rhs) { return lhs.first > rhs.first; });

    std::array<std::array<long long, size>, size> dp = {{0}};
    for (int i = 0; i < n; ++i)
    {
        for (int x = 0; x <= i; ++x)
        {
            int y        = i - x;
            dp[x + 1][y] = std::max(dp[x + 1][y], dp[x][y] + std::abs(score[i].first * (score[i].second - x)));
            dp[x][y + 1] = std::max(dp[x][y + 1], dp[x][y] + std::abs(score[i].first * (n - 1 - y - score[i].second)));
        }
    }

    long long result = 0;
    for (int i = 0; i <= n; ++i)
    {
        result = std::max(dp[i][n - i], result);
    }
    std::cout << result << std::endl;

    return 0;
}
