mex pairwise computation and more