Mistake in stack solution to ZCO Rectangles

I’ve been trying to solve this problem called [Rectangles][1] from ZCO. My solution is based on the stack data structure.

But there is some mistake in my code that I’m unable to find. My code gives AC for Task #5, #6 and #7.

Can anyone please point out where there is a mistake in my code?

Link to my


[2].


  [1]: https://www.codechef.com/ZCOPRAC/problems/ZCO15004
  [2]: http://pastebin.com/SWnnYeHw