http://www.codechef.com/MAY14/problems/CHEFBM