WA in TOURNAM :(

I was trying to solve this problem
but i don’t know why i’m getting WA.

here is my solution

I have tested my solution against a accpeted one one ideone, but it is givin correct output

Please anyone help me.