Added code for handling the second puzzle in the problem