algo3: hw6: in the middle