/**
 * Given a dictionary, modify the value of the item at the intersection of two given keys,
 * by concatenating it with the given value.
 *
 * Example:
 * dictionary = mapOf('a' to mapOf('x' to "hello", 'y' to "world"), 'b' to mapOf('z' to "Python"))
 * key1 = "a"
 * key2 = "x"
 * value = " there"
 *
 * The modified dictionary should become:
 * mapOf('a' to mapOf('x' to "hello there", 'y' to "world"), 'b' to mapOf('z' to "Python"))
 */
fun modifyDictionary(dictionary: MutableMap<String, MutableMap<String, String>>, key1: String, key2: String, value: String): Any {

    if (!dictionary.containsKey(key1) || dictionary[key1] !is MutableMap<*, *>) {
        return "Invalid key1"
    }

    if (key2 !in dictionary[key1]!!) {
        return "Invalid key2"
    }

    dictionary[key1]!![key2] = dictionary[key1]!![key2] + value
    return dictionary
}
/**
 * Given a dictionary, modify the value of the item at the intersection of two given keys,
 * by concatenating it with the given value.
 *
 * Example:
 * dictionary = mapOf('a' to mapOf('x' to "hello", 'y' to "world"), 'b' to mapOf('z' to "Python"))
 * key1 = "a"
 * key2 = "x"
 * value = " there"
 *
 * The modified dictionary should become:
 * mapOf('a' to mapOf('x' to "hello there", 'y' to "world"), 'b' to mapOf('z' to "Python"))
 */
fun modifyDictionary(dictionary: MutableMap<String, MutableMap<String, String>>, key1: String, key2: String, value: String): Any {
/**
 * Given a dictionary, modify the value of the item at the intersection of two given keys,
 * by concatenating it with the given value.
 *
 * Example:
 * dictionary = mapOf('a' to mapOf('x' to "hello", 'y' to "world"), 'b' to mapOf('z' to "Python"))
 * key1 = "a"
 * key2 = "x"
 * value = " there"
 *
 * The modified dictionary should become:
 * mapOf('a' to mapOf('x' to "hello there", 'y' to "world"), 'b' to mapOf('z' to "Python"))
 */
fun modifyDictionary(dictionary: MutableMap<String, MutableMap<String, String>>, key1: String, key2: String, value: String): Any {

    if (!dictionary.containsKey(key1) || dictionary[key1] !is MutableMap<*, *>) {
        return "Invalid key1"
    }

    if (key2 !in dictionary[key1]!!) {
        return "Invalid key2"
    }

    dictionary[key1]!![key2] = dictionary[key1]!![key2] + value
    return dictionary
}