using nth-element from header algorithm