SPOJ, Problem PRATA

Please refer to the code here: -

I am getting wrong answers for all testcases.