#include int main() { size_t N; std::cin >> N; std::vector P(N); for (auto &e : P) { std::cin >> e; } std::vector> D(N, std::vector(N + 1)); for (size_t i = 0; i < N - 1; ++i) { std::vector R(N + 1); for (size_t j = 0; j <= i; ++j) { ++R[P[j]]; } for (size_t j = 1; j <= N; ++j) { R[j] += R[j - 1]; } size_t sum = 0; for (size_t j = i + 1; j < N; ++j) { sum += R[N] - R[P[j]]; D[i + 1][j + 1] = sum; } } std::vector> dp(N + 1, std::vector(N + 1, N * N)); dp[0][0] = 0; for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < N; ++j) { for (size_t k = i + 1; k <= N; ++k) { dp[k][j + 1] = std::min(dp[k][j + 1], dp[i][j] + D[i][k]); } } } for (size_t i = 1; i <= N; ++i) { std::cout << dp[N][i] << std::endl; } }