ThreeSum algorithm