import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import           Data.Array.IO
import           Data.Array.MArray
import           Data.Maybe

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

(!?) :: IOUArray Int Int -> Int -> IO (Maybe Int)
a !? i = do
    (_, t) <- getBounds a
    if i < 1 || t < i
        then return Nothing
        else Just <$> readArray a i

printHeap :: IOUArray Int Int -> IO ()
printHeap a = do
    (_, e) <- getBounds a
    forM_ [1 .. e] $ \i -> do
        key <- readArray a i
        mparent <- a !? (i `div` 2)
        mleft   <- a !? (i * 2)
        mright  <- a !? (i * 2 + 1)
        putStr $ "node "  ++ show i   ++ ": "
        putStr $ "key = " ++ show key ++ ", "
        when (isJust mparent) $ do
            putStr $ "parent key = " ++ show (fromJust mparent) ++ ", "
        when (isJust mleft) $ do
            putStr $ "left key = "   ++ show (fromJust mleft)   ++ ", "
        when (isJust mright) $ do
            putStr $ "right key = "  ++ show (fromJust mright)  ++ ", "
        putStrLn ""

main :: IO ()
main = do
    n <- readLn
    xs <- (-1 :) . fmap readi . B.words <$> B.getLine
    ary <- newListArray (0, n) xs :: IO (IOUArray Int Int)
    printHeap ary

