2sum and median maintenance