Not complete solution for ONP problem - http://www.codechef.com/problems/ONP