modified from 3sum