Solved CodeChef November Challenge problem #5