3-way partitioning