Optimization: no need to flush stdin if we can determine quickly that stdin's input buffer is empty.