Please help me! Can't find out what exaclty is wrong with this code?!

This is my code for the problem RBTREES.
https://www.codechef.com/viewsolution/37128058
Its passing all my test cases but online judge says wrong answer. I have no idea what is wrong. It’s probably something very simple but I can’t seem to find out what it is!

I have used the same logic as the editorial one.