Problems from topcoder. Div 2 Problem 3.