Locating the n-smallest and n-largest values