Algorithm program 6, median maintenance