FIRESC help

I am getting NZEC error for this question. I tried the test cases and I am getting right answer.
Please someone review my code. Thanks.
http://pastie.org/9450013

//