/**
 * Given two nested lists, concatenate them and repeat the result a specified number of times.
 *
 * @param list1 A nested list.
 * @param list2 Another nested list.
 * @param numRepeats Number of times to repeat the concatenation.
 * @return The concatenated and repeated list.
 *
 * Example:
 * concatenateAndRepeatLists(listOf(listOf(1, 2), listOf(3, 4), listOf(5, 6)), listOf(listOf(7, 8)), 3)
 * // Output: [[1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [3, 4], [5, 6], [7, 8]]
 */
fun concatenateAndRepeatLists(list1: List<List<Int>>, list2: List<List<Int>>, numRepeats: Int): List<List<Int>> {

    // Concatenate the two lists
    val concatenatedList = list1 + list2

    // Repeat the concatenated list
    val repeatedList = concatenatedList.flatMap { it }.repeat(numRepeats)

    return repeatedList.chunked(concatenatedList[0].size)
}

fun List<Int>.repeat(times: Int): List<Int> {
    return List(size * times) { this[it % size] }
}
/**
 * Given two nested lists, concatenate them and repeat the result a specified number of times.
 *
 * @param list1 A nested list.
 * @param list2 Another nested list.
 * @param numRepeats Number of times to repeat the concatenation.
 * @return The concatenated and repeated list.
 *
 * Example:
 * concatenateAndRepeatLists(listOf(listOf(1, 2), listOf(3, 4), listOf(5, 6)), listOf(listOf(7, 8)), 3)
 * // Output: [[1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [3, 4], [5, 6], [7, 8]]
 */
fun concatenateAndRepeatLists(list1: List<List<Int>>, list2: List<List<Int>>, numRepeats: Int): List<List<Int>> {
/**
 * Given two nested lists, concatenate them and repeat the result a specified number of times.
 *
 * @param list1 A nested list.
 * @param list2 Another nested list.
 * @param numRepeats Number of times to repeat the concatenation.
 * @return The concatenated and repeated list.
 *
 * Example:
 * concatenateAndRepeatLists(listOf(listOf(1, 2), listOf(3, 4), listOf(5, 6)), listOf(listOf(7, 8)), 3)
 * // Output: [[1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [3, 4], [5, 6], [7, 8]]
 */
fun concatenateAndRepeatLists(list1: List<List<Int>>, list2: List<List<Int>>, numRepeats: Int): List<List<Int>> {

    // Concatenate the two lists
    val concatenatedList = list1 + list2

    // Repeat the concatenated list
    val repeatedList = concatenatedList.flatMap { it }.repeat(numRepeats)

    return repeatedList.chunked(concatenatedList[0].size)
}

fun List<Int>.repeat(times: Int): List<Int> {
    return List(size * times) { this[it % size] }
}