https://www.codechef.com/problems/CHEFEZQ

i just applied a flag and assigned the values to the answers i was getting and it worked.
but i do wanna know why this submission of mine is not as the logic is same
https://www.codechef.com/viewsolution/38955939