Piyush and magical park

getting two test cases failed , why ?

I have edited your code… Try to submit now…
By mistake you have interchanged n and m in your loop… Rest code was fine…