My solution to topcoder SRM157 DIV2