val nodeList = arrayListOf<Long?>(null)

fun main(args: Array<String>) {

    val nodeCount = readLine()!!.toInt()

    val nodeKeys = readLine()!!.split(" ")

    // ヒープに格納
    for (i in 1..nodeCount) {
        nodeList.add(i, nodeKeys[i - 1].toLong())
    }

    // 表示
    for (i in 1..nodeCount) {

        val parentNodeKey = getParentNode(i)
        val leftNodeKey = getLeftNode(i)
        val rightNodeKey = getRightNode(i)

        var label = "node $i: key = ${nodeList[i]}, "
        if (parentNodeKey != null) {
            label += "parent key = $parentNodeKey, "
        }
        if (leftNodeKey != null) {
            label += "left key = $leftNodeKey, "
        }
        if (rightNodeKey != null) {
            label += "right key = $rightNodeKey, "
        }
        println(label)
    }
}


fun getLeftNode(index: Int): Long? {
    val leftNodeIndex = index * 2
    return nodeList.getOrNull(leftNodeIndex)
}

fun getRightNode(index: Int): Long? {
    val rightNodeIndex = index * 2 + 1
    return nodeList.getOrNull(rightNodeIndex)
}

fun getParentNode(index: Int): Long? {
    val parentNodeIndex = Math.floor(index.toDouble() / 2).toInt()
    return nodeList.getOrNull(parentNodeIndex)
}
