Not Getting a correct output for SPOJ - SEQ problem