Piyush and magical park problem

this is my code https://ide.codingblocks.com/s/247052
not one test case is correct
kindly help me out