TopCoder SRM 626 div 2 Problem 3 NegativeGraphDiv2