The final solution for the problem #24