/**
 * Given two nested lists, append each element of list2 to the corresponding sublist in list1.
 *
 * @param list1 A nested list containing sublists.
 * @param list2 A list containing elements to be appended to sublists of list1.
 * @return The modified list1 with elements appended from list2.
 * @throws IllegalArgumentException If the lengths of list1 and list2 are not equal.
 *
 * Example:
 * val list1 = mutableListOf(mutableListOf(1, 2), mutableListOf(3, 4))
 * val list2 = listOf(5, 6)
 * appendListElements(list1, list2)  // Output: [[1, 2, 5], [3, 4, 6]]
 */
fun appendListElements(list1: MutableList<MutableList<Int>>, list2: List<Int>): MutableList<MutableList<Int>> {

    if (list1.size != list2.size) {
        throw IllegalArgumentException("The lengths of list1 and list2 must be equal.")
    }

    for (i in list1.indices) {
        list1[i].add(list2[i])
    }

    return list1
}
/**
 * Given two nested lists, append each element of list2 to the corresponding sublist in list1.
 *
 * @param list1 A nested list containing sublists.
 * @param list2 A list containing elements to be appended to sublists of list1.
 * @return The modified list1 with elements appended from list2.
 * @throws IllegalArgumentException If the lengths of list1 and list2 are not equal.
 *
 * Example:
 * val list1 = mutableListOf(mutableListOf(1, 2), mutableListOf(3, 4))
 * val list2 = listOf(5, 6)
 * appendListElements(list1, list2)  // Output: [[1, 2, 5], [3, 4, 6]]
 */
fun appendListElements(list1: MutableList<MutableList<Int>>, list2: List<Int>): MutableList<MutableList<Int>> {
/**
 * Given two nested lists, append each element of list2 to the corresponding sublist in list1.
 *
 * @param list1 A nested list containing sublists.
 * @param list2 A list containing elements to be appended to sublists of list1.
 * @return The modified list1 with elements appended from list2.
 * @throws IllegalArgumentException If the lengths of list1 and list2 are not equal.
 *
 * Example:
 * val list1 = mutableListOf(mutableListOf(1, 2), mutableListOf(3, 4))
 * val list2 = listOf(5, 6)
 * appendListElements(list1, list2)  // Output: [[1, 2, 5], [3, 4, 6]]
 */
fun appendListElements(list1: MutableList<MutableList<Int>>, list2: List<Int>): MutableList<MutableList<Int>> {

    if (list1.size != list2.size) {
        throw IllegalArgumentException("The lengths of list1 and list2 must be equal.")
    }

    for (i in list1.indices) {
        list1[i].add(list2[i])
    }

    return list1
}