polar bear Menshykov Uslada zoo St Petersburg elephant Horace zoo Kiev decide paint as try create masterpiece draft piece paper the draft consist n segment each segment horizontal vertical Now friend want simplify draft delete segment part segment final masterpiece meet condition Horace want able paint picture stroke put brush paper take picture ready the brush paint place multiple time that s remain segment form single connected shape Menshykov want result shape simple he define simple shape shape do not contain cycle Initially segment draft integer startpoint endpoint coordinate Uslada do not like real coordinate want condition fulfil change as part draft beautiful friend decide delete part draft sum length remain segment large possible your task count maximum sum length remain extra segment remove