Solution for Code Chef Problem 'ONP' (http://www.codechef.com/problems/ONP)