Median Maintenance algorithm implementation