TopCoder SRM 379: Div 2 - 250 solution code