for n <= 2*10^5 --> read all numbers and use direct nth_element (or your own implementation of Kth order statistics). for n > 2*10^5 --> read only 2*10^5 numbers and use nth_element for n - 2*10^5, and remove first n - 2*10^5, i.e. rewrite remain numbers to first n-2*10^5, and again use nth_element for n/2 - (n- 2*10^5)