top coder solution