solved 594 div2 250pt problem