/**
 * The function takes in two nested tuples (tuple1 and tuple2) and a single element as arguments.
 * It returns a nested tuple containing the intersection of tuple1 and tuple2, after appending the given element to the end of the resulting tuple.
 *
 * Example:
 * tuple1 = ((1, 2, 3), (4, 5, 6))
 * tuple2 = ((3, 4, 5), (6, 7, 8))
 * element = 9
 * intersection(tuple1, tuple2, element) => ((3, 4, 5), (6, 7, 8), 9)
 */
fun intersection(tuple1: List<List<Int>>, tuple2: List<List<Int>>, element: Int): List<Any> {

    val intersectionList = mutableListOf<List<Int>>()

    for (subTuple in tuple1) {
        if (subTuple in tuple2) {
            intersectionList.add(subTuple)
        }
    }

    return intersectionList.flatten() + element
}
/**
 * The function takes in two nested tuples (tuple1 and tuple2) and a single element as arguments.
 * It returns a nested tuple containing the intersection of tuple1 and tuple2, after appending the given element to the end of the resulting tuple.
 *
 * Example:
 * tuple1 = ((1, 2, 3), (4, 5, 6))
 * tuple2 = ((3, 4, 5), (6, 7, 8))
 * element = 9
 * intersection(tuple1, tuple2, element) => ((3, 4, 5), (6, 7, 8), 9)
 */
fun intersection(tuple1: List<List<Int>>, tuple2: List<List<Int>>, element: Int): List<Any> {
/**
 * The function takes in two nested tuples (tuple1 and tuple2) and a single element as arguments.
 * It returns a nested tuple containing the intersection of tuple1 and tuple2, after appending the given element to the end of the resulting tuple.
 *
 * Example:
 * tuple1 = ((1, 2, 3), (4, 5, 6))
 * tuple2 = ((3, 4, 5), (6, 7, 8))
 * element = 9
 * intersection(tuple1, tuple2, element) => ((3, 4, 5), (6, 7, 8), 9)
 */
fun intersection(tuple1: List<List<Int>>, tuple2: List<List<Int>>, element: Int): List<Any> {

    val intersectionList = mutableListOf<List<Int>>()

    for (subTuple in tuple1) {
        if (subTuple in tuple2) {
            intersectionList.add(subTuple)
        }
    }

    return intersectionList.flatten() + element
}