/**
 * Given a list of animal species and a list of habitats, count the number of species
 * that are found in all the given habitats.
 *
 * @param animalList A list of animal species.
 * @param habitatList A list of habitats.
 * @return The total number of species found in all the given habitats.
 */
fun countSpecies(animalList: List<String>, habitatList: List<Set<String>>): Int {

    var commonSpecies = habitatList[0].toMutableSet() // Initialize the set with the first habitat's species

    for (habitat in habitatList.subList(1, habitatList.size)) { // Loop through the remaining habitats
        commonSpecies.retainAll(habitat) // Find the intersection with the new habitat's species
    }

    return commonSpecies.size // Return the total number of common species
}
/**
 * Given a list of animal species and a list of habitats, count the number of species
 * that are found in all the given habitats.
 *
 * @param animalList A list of animal species.
 * @param habitatList A list of habitats.
 * @return The total number of species found in all the given habitats.
 */
fun countSpecies(animalList: List<String>, habitatList: List<Set<String>>): Int {
/**
 * Given a list of animal species and a list of habitats, count the number of species
 * that are found in all the given habitats.
 *
 * @param animalList A list of animal species.
 * @param habitatList A list of habitats.
 * @return The total number of species found in all the given habitats.
 */
fun countSpecies(animalList: List<String>, habitatList: List<Set<String>>): Int {

    var commonSpecies = habitatList[0].toMutableSet() // Initialize the set with the first habitat's species

    for (habitat in habitatList.subList(1, habitatList.size)) { // Loop through the remaining habitats
        commonSpecies.retainAll(habitat) // Find the intersection with the new habitat's species
    }

    return commonSpecies.size // Return the total number of common species
}