/**
 * Given a tuple 't' and an integer 'n', return a list of tuples that contains the intersection of the
 * original tuple and its elements indexed by 'n'.
 *
 * @param t The input tuple.
 * @param n The index to be used for indexing tuples within the original tuple.
 * @return A list of tuples containing the intersection of 't' and 't[i]' where 'i' is 'n'.
 */
fun psychologistExercise(t: List<Any>, n: Int): List<Pair<Any, Any>> {

    // Use set to find the common elements between 't' and 't[i]'
    val intersection = t.filterIndexed { index, _ -> index == n }.toSet().intersect(t)

    // Create a list of tuples by pairing the common element with each corresponding element in 't'
    val result = t.mapIndexed { index, ele -> Pair(ele, t[index]) }.filter { it.first in intersection }

    return result
}
/**
 * Given a tuple 't' and an integer 'n', return a list of tuples that contains the intersection of the
 * original tuple and its elements indexed by 'n'.
 *
 * @param t The input tuple.
 * @param n The index to be used for indexing tuples within the original tuple.
 * @return A list of tuples containing the intersection of 't' and 't[i]' where 'i' is 'n'.
 */
fun psychologistExercise(t: List<Any>, n: Int): List<Pair<Any, Any>> {
/**
 * Given a tuple 't' and an integer 'n', return a list of tuples that contains the intersection of the
 * original tuple and its elements indexed by 'n'.
 *
 * @param t The input tuple.
 * @param n The index to be used for indexing tuples within the original tuple.
 * @return A list of tuples containing the intersection of 't' and 't[i]' where 'i' is 'n'.
 */
fun psychologistExercise(t: List<Any>, n: Int): List<Pair<Any, Any>> {

    // Use set to find the common elements between 't' and 't[i]'
    val intersection = t.filterIndexed { index, _ -> index == n }.toSet().intersect(t)

    // Create a list of tuples by pairing the common element with each corresponding element in 't'
    val result = t.mapIndexed { index, ele -> Pair(ele, t[index]) }.filter { it.first in intersection }

    return result
}