Correcting max flips algorithm.