
H = gets.to_i
array = gets.split.map &:to_i
nodes = Array.new
array.each_with_index do |a,idx|
  nodes[idx+1] = a
end

class << nodes
  def puts_info
    self.each_with_index do |node, idx|
      next if node.nil?
      print "node #{idx}: key = #{node}, "
      print "parent key = #{self[parent(idx)]}, " if self[parent(idx)]
      print "left key = #{self[left(idx)]}, " if self[left(idx)]
      print "right key = #{self[right(idx)]}, " if self[right(idx)]
      print "\n"
    end
  end
end

def parent(int)
  int / 2
end

def left(int)
  int * 2
end

def right(int)
  int * 2 + 1
end

nodes.puts_info

