fun main(args: Array<String>) {
    val array = IntArray(readLine()?.toInt()?.plus(1) ?: 0)
    readLine()?.split(" ".toRegex())
        ?.map(String::toInt)
        ?.forEachIndexed { index, value ->
            array[index + 1] = value
        }
    for(i in 1..array.lastIndex) {
        println("node $i: key = ${array[i]}, ${if (i != 1) {
            "parent key = ${array[parent(i)]}, "
        } else {
            ""
        }
        }${if (left(i) <= array.lastIndex) {
            "left key = ${array[left(i)]}, "
        } else {
            ""
        }
        }${if (right(i) <= array.lastIndex) {
            "right key = ${array[right(i)]}, "
        } else {
            ""
        }
        }")
    }
}

fun parent(index: Int) = index / 2
fun left(index: Int) = index * 2
fun right(index: Int) = index * 2 + 1
