http://www.codechef.com/JAN14/problems/MTRICK