same algorithm as 3Sum