Up to here has been done the sorting from the problem solution