/**
 * Given two lists l1 and l2, find the intersection of these lists,
 * append the newElements to the intersection, and return the updated intersection.
 *
 * @param l1 First list.
 * @param l2 Second list.
 * @param newElements List of new elements to append to the intersection.
 * @return Updated intersection of l1 and l2 with newElements appended.
 */
fun intersectionEqualAppend(l1: List<Any>, l2: List<Any>, newElements: List<Any>): List<Any> {

    val intersection = mutableListOf<Any>()

    // Find the intersection of l1 and l2
    for (element in l1) {
        if (element in l2 && element !in intersection) {
            intersection.add(element)
        }
    }

    // Append newElements to the intersection
    for (element in newElements) {
        if (element !in intersection) {
            intersection.add(element)
        }
    }

    return intersection
}
/**
 * Given two lists l1 and l2, find the intersection of these lists,
 * append the newElements to the intersection, and return the updated intersection.
 *
 * @param l1 First list.
 * @param l2 Second list.
 * @param newElements List of new elements to append to the intersection.
 * @return Updated intersection of l1 and l2 with newElements appended.
 */
fun intersectionEqualAppend(l1: List<Any>, l2: List<Any>, newElements: List<Any>): List<Any> {
/**
 * Given two lists l1 and l2, find the intersection of these lists,
 * append the newElements to the intersection, and return the updated intersection.
 *
 * @param l1 First list.
 * @param l2 Second list.
 * @param newElements List of new elements to append to the intersection.
 * @return Updated intersection of l1 and l2 with newElements appended.
 */
fun intersectionEqualAppend(l1: List<Any>, l2: List<Any>, newElements: List<Any>): List<Any> {

    val intersection = mutableListOf<Any>()

    // Find the intersection of l1 and l2
    for (element in l1) {
        if (element in l2 && element !in intersection) {
            intersection.add(element)
        }
    }

    // Append newElements to the intersection
    for (element in newElements) {
        if (element !in intersection) {
            intersection.add(element)
        }
    }

    return intersection
}