Getting wrong answer in SPAMCLAS problem

The code generates correct output on code chef IDE but it gives WA on submitting the same.

solution: https://www.codechef.com/viewsolution/20334073

//