/**
 * Given a 3-dimensional array representing different layers of minerals in a geological formation,
 * this function determines the number of minerals that are present in the intersection of each layer.
 *
 * @param layers A 3-dimensional list where each element represents a layer and the nested elements
 * represent the minerals present in that layer.
 * @return The number of minerals that are present in the intersection of all layers.
 */
fun countMinerals(layers: List<List<List<String>>>) : Int {

    // Initialize a set to store the common minerals across all layers
    var commonMinerals = layers[0].toSet()

    // Iterate through the layers starting from the second layer
    for (layer in layers.subList(1, layers.size)) {
        // Find the intersection of current common minerals and the minerals of the current layer
        commonMinerals = commonMinerals.intersect(layer).toSet()
    }

    // Return the count of common minerals
    return commonMinerals.size
}
/**
 * Given a 3-dimensional array representing different layers of minerals in a geological formation,
 * this function determines the number of minerals that are present in the intersection of each layer.
 *
 * @param layers A 3-dimensional list where each element represents a layer and the nested elements
 * represent the minerals present in that layer.
 * @return The number of minerals that are present in the intersection of all layers.
 */
fun countMinerals(layers: List<List<List<String>>>) : Int {
/**
 * Given a 3-dimensional array representing different layers of minerals in a geological formation,
 * this function determines the number of minerals that are present in the intersection of each layer.
 *
 * @param layers A 3-dimensional list where each element represents a layer and the nested elements
 * represent the minerals present in that layer.
 * @return The number of minerals that are present in the intersection of all layers.
 */
fun countMinerals(layers: List<List<List<String>>>) : Int {

    // Initialize a set to store the common minerals across all layers
    var commonMinerals = layers[0].toSet()

    // Iterate through the layers starting from the second layer
    for (layer in layers.subList(1, layers.size)) {
        // Find the intersection of current common minerals and the minerals of the current layer
        commonMinerals = commonMinerals.intersect(layer).toSet()
    }

    // Return the count of common minerals
    return commonMinerals.size
}