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