DEFECTS problem

why is this solution giving the wrong answer even though it is working correctly for all the examples
https://www.codechef.com/viewsolution/29443551