/**
 * Given the number of turtles and their corresponding colors, as well as the number of brushes and their available colors,
 * this function returns the common colors that can be used by all the turtles.
 *
 * @param turtleCount An integer representing the total number of turtles.
 * @param turtleColors A list containing the colors associated with each turtle.
 * @param brushCount An integer representing the total number of available brushes.
 * @param brushColors A set containing the colors of the available brushes.
 * @return A set containing the common colors that can be used by all the turtles.
 */
fun getCommonColors(turtleCount: Int, turtleColors: List<String>, brushCount: Int, brushColors: Set<String>): Set<String> {

    val commonColors = mutableSetOf<String>()
    for ((turtleId, turtleColor) in turtleColors.withIndex()) {
        for (brushColor in brushColors) {
            if (turtleColor == brushColor) {
                commonColors.add(turtleColor)
            }
            if (commonColors.size == turtleCount) {
                return commonColors
            }
        }
    }
    return commonColors
}

// Example usage
val turtleCount = 3
val turtleColors = listOf("red", "blue", "green")
val brushCount = 5
val brushColors = setOf("red")
/**
 * Given the number of turtles and their corresponding colors, as well as the number of brushes and their available colors,
 * this function returns the common colors that can be used by all the turtles.
 *
 * @param turtleCount An integer representing the total number of turtles.
 * @param turtleColors A list containing the colors associated with each turtle.
 * @param brushCount An integer representing the total number of available brushes.
 * @param brushColors A set containing the colors of the available brushes.
 * @return A set containing the common colors that can be used by all the turtles.
 */
fun getCommonColors(turtleCount: Int, turtleColors: List<String>, brushCount: Int, brushColors: Set<String>): Set<String> {
/**
 * Given the number of turtles and their corresponding colors, as well as the number of brushes and their available colors,
 * this function returns the common colors that can be used by all the turtles.
 *
 * @param turtleCount An integer representing the total number of turtles.
 * @param turtleColors A list containing the colors associated with each turtle.
 * @param brushCount An integer representing the total number of available brushes.
 * @param brushColors A set containing the colors of the available brushes.
 * @return A set containing the common colors that can be used by all the turtles.
 */
fun getCommonColors(turtleCount: Int, turtleColors: List<String>, brushCount: Int, brushColors: Set<String>): Set<String> {

    val commonColors = mutableSetOf<String>()
    for ((turtleId, turtleColor) in turtleColors.withIndex()) {
        for (brushColor in brushColors) {
            if (turtleColor == brushColor) {
                commonColors.add(turtleColor)
            }
            if (commonColors.size == turtleCount) {
                return commonColors
            }
        }
    }
    return commonColors
}

// Example usage
val turtleCount = 3
val turtleColors = listOf("red", "blue", "green")
val brushCount = 5
val brushColors = setOf("red")