Partitioning with duplication handling and pivot choosing quicksort