what is wrong with this code for DevuLand, Dinosaurs and Laddus problem

Here’s the question link -

code deleted

It gives the right answer for all the test I do, but when i submit it, it gives wrong answer.