TREE HOUSES only first two cases passing

https://www.codechef.com/viewsolution/46629002

I have also written almost the same code for the long challenge of THOUSES but only first two cases only plz help me to understand where’s the code is getting wrong.