/**
 * Given a nested dictionary, access a specific value using try-except statements
 */
fun accessNestedDict(dictionary: Map<String, Any>): Pair<Any?, Any?> {

    try {
        // Attempt to access nested dictionary values
        val value1 = (dictionary["key1"] as Map<*, *>?)?.get("key2")?.let { (it as Map<*, *>).get("key3") }
        val value2 = (dictionary["key4"] as Map<*, *>?)?.get("key5")?.let { (it as Map<*, *>).get("key6") }

        return Pair(value1, value2)
    } catch (e: ClassCastException) {
        // If any intermediate value is not a dictionary, print an error message and return null
        println("One or more intermediate values in the nested dictionary are not dictionaries")
    } catch (e: Exception) {
        // Catch any other exceptions and print an error message
        println("An error occurred while accessing the values in the nested dictionary")
    }

    // If any exception occurs, return null for both values
    return Pair(null, null)
}

// Example usage
val nestedDict = mapOf("key1" to mapOf("key2" to mapOf("key3" to "value1")), "key4" to mapOf("key5" to 5))
val result = accessNestedDict(nestedDict)
/**
 * Given a nested dictionary, access a specific value using try-except statements
 */
fun accessNestedDict(dictionary: Map<String, Any>): Pair<Any?, Any?> {
/**
 * Given a nested dictionary, access a specific value using try-except statements
 */
fun accessNestedDict(dictionary: Map<String, Any>): Pair<Any?, Any?> {

    try {
        // Attempt to access nested dictionary values
        val value1 = (dictionary["key1"] as Map<*, *>?)?.get("key2")?.let { (it as Map<*, *>).get("key3") }
        val value2 = (dictionary["key4"] as Map<*, *>?)?.get("key5")?.let { (it as Map<*, *>).get("key6") }

        return Pair(value1, value2)
    } catch (e: ClassCastException) {
        // If any intermediate value is not a dictionary, print an error message and return null
        println("One or more intermediate values in the nested dictionary are not dictionaries")
    } catch (e: Exception) {
        // Catch any other exceptions and print an error message
        println("An error occurred while accessing the values in the nested dictionary")
    }

    // If any exception occurs, return null for both values
    return Pair(null, null)
}

// Example usage
val nestedDict = mapOf("key1" to mapOf("key2" to mapOf("key3" to "value1")), "key4" to mapOf("key5" to 5))
val result = accessNestedDict(nestedDict)