Added 3-way partition based on lumoto's method