Need Help! RECTANGLE Problem

I am getting WA only for first testcase. All other testcases are AC. Please guide me.
LInk: CodeChef: Practical coding for everyone
I find the smallest element to the left and right.