54. Pairwise algorithm