A new invariant, adjust the algorithm