apple pie's submission of End Sorted | CodeChef