Click here to read the complete problem statement.
The numbers of such pairs should be much much larger than 867