/**
 * Given nested dictionary 'data' containing information about different organisms,
 * complete the code to count the number of occurrences of each species.
 *
 * @param data Nested dictionary containing information about organisms
 * @return A dictionary where keys are species names and values are their respective counts.
 */
fun countSpecies(data: Map<String, Map<String, Any>>): Map<String, Int> {

    val speciesCounts = mutableMapOf<String, Int>()

    // Iterate over each organism
    for (organism in data.values) {
        // Iterate over each feature of the organism
        for (feature in organism.values) {
            // Check if the feature is a nested dictionary representing a species occurrence
            if (feature is Map<*, *>) {
                // Iterate over each occurrence of the species
                for (occurrence in feature.values) {
                    // Check if the species name is already present in speciesCounts map
                    if (occurrence is String) {
                        // Increment the count for the species by 1
                        speciesCounts[occurrence] = speciesCounts.getOrDefault(occurrence, 0) + 1
                    }
                }
            }
        }
    }

    return speciesCounts
}
/**
 * Given nested dictionary 'data' containing information about different organisms,
 * complete the code to count the number of occurrences of each species.
 *
 * @param data Nested dictionary containing information about organisms
 * @return A dictionary where keys are species names and values are their respective counts.
 */
fun countSpecies(data: Map<String, Map<String, Any>>): Map<String, Int> {
/**
 * Given nested dictionary 'data' containing information about different organisms,
 * complete the code to count the number of occurrences of each species.
 *
 * @param data Nested dictionary containing information about organisms
 * @return A dictionary where keys are species names and values are their respective counts.
 */
fun countSpecies(data: Map<String, Map<String, Any>>): Map<String, Int> {

    val speciesCounts = mutableMapOf<String, Int>()

    // Iterate over each organism
    for (organism in data.values) {
        // Iterate over each feature of the organism
        for (feature in organism.values) {
            // Check if the feature is a nested dictionary representing a species occurrence
            if (feature is Map<*, *>) {
                // Iterate over each occurrence of the species
                for (occurrence in feature.values) {
                    // Check if the species name is already present in speciesCounts map
                    if (occurrence is String) {
                        // Increment the count for the species by 1
                        speciesCounts[occurrence] = speciesCounts.getOrDefault(occurrence, 0) + 1
                    }
                }
            }
        }
    }

    return speciesCounts
}