find number of complementary pairs in array