/**
 * This function takes in a set of athletes and a list of indices, and returns the intersection of all the athletes
 * at the given indices.
 *
 * @param athleteSet A set of athletes.
 * @param indexList A list of indices.
 * @return A set containing the intersection of all the athletes at the given indices.
 */
fun getIntersection(athleteSet: Set<String>, indexList: List<Int>): Set<String> {

    // Initialize an empty set to store the intersection of athletes
    val intersection = mutableSetOf<String>()

    // Iterate over each index in the list
    for (index in indexList) {
        // Check if the index is within the valid range
        if (index >= 0 && index < athleteSet.size) {
            // Get the athlete at the current index
            val athlete = athleteSet.elementAt(index)
            // Add the athlete to the intersection set
            intersection.add(athlete)
        }
    }

    // Return the final intersection set
    return intersection
}

// Example usage
val athleteSet = setOf("John", "Emily", "Michael", "Sarah", "David")
val indexList = listOf(3, 0, 2, 1, 4)

val intersection = getIntersection(athleteSet, indexList)
/**
 * This function takes in a set of athletes and a list of indices, and returns the intersection of all the athletes
 * at the given indices.
 *
 * @param athleteSet A set of athletes.
 * @param indexList A list of indices.
 * @return A set containing the intersection of all the athletes at the given indices.
 */
fun getIntersection(athleteSet: Set<String>, indexList: List<Int>): Set<String> {
/**
 * This function takes in a set of athletes and a list of indices, and returns the intersection of all the athletes
 * at the given indices.
 *
 * @param athleteSet A set of athletes.
 * @param indexList A list of indices.
 * @return A set containing the intersection of all the athletes at the given indices.
 */
fun getIntersection(athleteSet: Set<String>, indexList: List<Int>): Set<String> {

    // Initialize an empty set to store the intersection of athletes
    val intersection = mutableSetOf<String>()

    // Iterate over each index in the list
    for (index in indexList) {
        // Check if the index is within the valid range
        if (index >= 0 && index < athleteSet.size) {
            // Get the athlete at the current index
            val athlete = athleteSet.elementAt(index)
            // Add the athlete to the intersection set
            intersection.add(athlete)
        }
    }

    // Return the final intersection set
    return intersection
}

// Example usage
val athleteSet = setOf("John", "Emily", "Michael", "Sarah", "David")
val indexList = listOf(3, 0, 2, 1, 4)

val intersection = getIntersection(athleteSet, indexList)