/**
 * Given a nested list and a list of indices, this function returns the specified element by accessing the nested
 * elements using the provided indices. If any index is out of bounds, it returns null.
 *
 * Example:
 * nestedList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
 * indices = listOf(0, 1, 2)
 * getNestedElement(nestedList, indices) => 3
 *
 * @param nestedList A nested list containing elements to be accessed
 * @param indices A list of indices to access nested elements
 * @return The element at the specified indices, or null if any index is out of bounds
 */
fun getNestedElement(nestedList: List<List<Any>>, indices: List<Int>): Any? {

    var currentList: Any? = nestedList as Any
    for (index in indices) {
        if (currentList is List<*> && index in 0 until (currentList as List<*>).size) {
            currentList = (currentList as List<*>)[index]
        } else {
            return null
        }
    }
    return currentList
}
/**
 * Given a nested list and a list of indices, this function returns the specified element by accessing the nested
 * elements using the provided indices. If any index is out of bounds, it returns null.
 *
 * Example:
 * nestedList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
 * indices = listOf(0, 1, 2)
 * getNestedElement(nestedList, indices) => 3
 *
 * @param nestedList A nested list containing elements to be accessed
 * @param indices A list of indices to access nested elements
 * @return The element at the specified indices, or null if any index is out of bounds
 */
fun getNestedElement(nestedList: List<List<Any>>, indices: List<Int>): Any? {
/**
 * Given a nested list and a list of indices, this function returns the specified element by accessing the nested
 * elements using the provided indices. If any index is out of bounds, it returns null.
 *
 * Example:
 * nestedList = listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))
 * indices = listOf(0, 1, 2)
 * getNestedElement(nestedList, indices) => 3
 *
 * @param nestedList A nested list containing elements to be accessed
 * @param indices A list of indices to access nested elements
 * @return The element at the specified indices, or null if any index is out of bounds
 */
fun getNestedElement(nestedList: List<List<Any>>, indices: List<Int>): Any? {

    var currentList: Any? = nestedList as Any
    for (index in indices) {
        if (currentList is List<*> && index in 0 until (currentList as List<*>).size) {
            currentList = (currentList as List<*>)[index]
        } else {
            return null
        }
    }
    return currentList
}