/**
 * This function takes two nested lists as input and returns a new list containing the common elements in the same order as they appear in the given lists.
 *
 * @param list1 First nested list.
 * @param list2 Second nested list.
 * @return New list containing common elements.
 */
fun nestedListIntersection(list1: List<List<Int>>, list2: List<List<Int>>): List<Int> {

    val result = mutableListOf<Int>()

    for (subList1 in list1) {
        for (subList2 in list2) {
            for (element1 in subList1) {
                for (element2 in subList2) {
                    if (element1 == element2) {
                        result.add(element1)
                    }
                }
            }
        }
    }

    return result
}
/**
 * This function takes two nested lists as input and returns a new list containing the common elements in the same order as they appear in the given lists.
 *
 * @param list1 First nested list.
 * @param list2 Second nested list.
 * @return New list containing common elements.
 */
fun nestedListIntersection(list1: List<List<Int>>, list2: List<List<Int>>): List<Int> {
/**
 * This function takes two nested lists as input and returns a new list containing the common elements in the same order as they appear in the given lists.
 *
 * @param list1 First nested list.
 * @param list2 Second nested list.
 * @return New list containing common elements.
 */
fun nestedListIntersection(list1: List<List<Int>>, list2: List<List<Int>>): List<Int> {

    val result = mutableListOf<Int>()

    for (subList1 in list1) {
        for (subList2 in list2) {
            for (element1 in subList1) {
                for (element2 in subList2) {
                    if (element1 == element2) {
                        result.add(element1)
                    }
                }
            }
        }
    }

    return result
}