pairs problem, slow solution