How is this solution getting AC?

aprilcookoff
problem

#1

http://www.codechef.com/viewsolution/3784470

Can somebody tell me how is this getting accepted. I ran it on ideone and it is giving wrong answer for the sample test cases.


#2

Some reason posting same question several times?


#3

Actually first I didn’t understand this solution, that’s why I posted a question about it. Later when my friend found out just printing “-2” is getting AC, he made it a separate question.


#4

I see now, I looked at it from question list and as you added comment there was same name in the list, sorry.