Polo and Palin

I am not able to solve "Polo and Palin (LUCKPOLO) posted in Technosurge 2013, can somebody help me out?

Try to understand the following code:
http://www.codechef.com/viewsolution/1862417

//