http://www.codechef.com/OCT13/problems/HELPLIRA/