TopCoder marathon match problem