Piyush and magical park

https://hack.codingblocks.com/app/practice/1/1051/problem
why all test cases are not passing?? although code seems to be correct only.