implementing maxViaFold.