Successful solution of problem Chef and Strange Matrix - http://www.codechef.com/MAY14/problems/CHEFBM