Better solution for 595 div2 500 pt problem