calculate the number of categories