Optimal grouping of researchers into departments