Persistent TLE in SPOJ Question GAMES (How Many Games)

I don’t know why i am getting persistent TLE.
Here is the link to my solution-http://ideone.com/27IIh7

//