Fixed algorithm for calculating pairs