SPOJ SIGABRT ERROR IN SPCS

My code is working fine for all the testcases in ideone and in mageia… but when i submit in spoj it shows SIGABRT error…
MY soln link :-- http://ideone.com/v0KuYL
Question link :-- http://www.spoj.com/problems/SPCS/
Thnx in advance for correction …