chefhack wrong answer

Can anybody tell me what is wrong with my solution??

My code

Question

In editorial there are some corner test cases, and I am not able to pass them. I know for which test cases it is wrong, but not the reason why I am getting the wrong answer. Any pointers would be helpful. Thanks in advance.