cardtrick spoj

I m trying a lot to solve this problem [cardtrick][1]. here is my


[2]..plz anyone help me..
any help will be appriciated..


  [1]: http://www.spoj.com/problems/CTRICK/
  [2]: http://ideone.com/FR9FzN