/**
 * Given a list of elements and a list of indices, this function modifies the elements in the list according to the given indices.
 *
 * @param elements A list of elements
 * @param indices A list of indices specifying the positions to modify
 * @return The modified list
 *
 * Example:
 * modifyListElements(listOf("apple", "banana", "cherry", "date"), listOf(1, 0, 3)) -> listOf("banana", "apple", "date", "date")
 */
fun modifyListElements(elements: List<String>, indices: List<Int>): List<String> {

    // Check if both lists have the same length
    if (elements.size != indices.size) {
        println("Invalid inputs! The list of elements and indices must have the same length.")
        return elements
    }

    // Create a copy of the original list to preserve it
    val result = elements.toMutableList()

    // Iterate through the indices and modify the corresponding elements
    for (i in indices.indices) {
        val index = indices[i]
        if (index in elements.indices) {
            result[index] = elements[(index + 1) % elements.size]
        }
    }

    return result
}

// Task 1: Modify selected elements
/**
 * Given a list of elements and a list of indices, this function modifies the elements in the list according to the given indices.
 *
 * @param elements A list of elements
 * @param indices A list of indices specifying the positions to modify
 * @return The modified list
 *
 * Example:
 * modifyListElements(listOf("apple", "banana", "cherry", "date"), listOf(1, 0, 3)) -> listOf("banana", "apple", "date", "date")
 */
fun modifyListElements(elements: List<String>, indices: List<Int>): List<String> {
/**
 * Given a list of elements and a list of indices, this function modifies the elements in the list according to the given indices.
 *
 * @param elements A list of elements
 * @param indices A list of indices specifying the positions to modify
 * @return The modified list
 *
 * Example:
 * modifyListElements(listOf("apple", "banana", "cherry", "date"), listOf(1, 0, 3)) -> listOf("banana", "apple", "date", "date")
 */
fun modifyListElements(elements: List<String>, indices: List<Int>): List<String> {

    // Check if both lists have the same length
    if (elements.size != indices.size) {
        println("Invalid inputs! The list of elements and indices must have the same length.")
        return elements
    }

    // Create a copy of the original list to preserve it
    val result = elements.toMutableList()

    // Iterate through the indices and modify the corresponding elements
    for (i in indices.indices) {
        val index = indices[i]
        if (index in elements.indices) {
            result[index] = elements[(index + 1) % elements.size]
        }
    }

    return result
}

// Task 1: Modify selected elements