pairwise function

Count pairs of items within a group