class Node
  def initialize(i, key)
    @index = i
    @key = key
    @parent_key = nil
    @left_key = nil
    @right_key = nil
  end

  def to_s
    str = "node #{index}: key = #{key}, "
    str += "parent_key = #{@parent_key.key}, " unless @parent_key.nil?
    str += "left_key = #{@left_key.key}, " unless @left_key.nil?
    str += "right_key = #{@right_key.key}, " unless @right_key.nil?
    str
  end

  attr_accessor :index, :key
  attr_writer :parent_key, :right_key, :left_key
end

h = gets.to_i
input = gets.split(' ').map(&:to_i)
heap = []
input.each_with_index do |value, index|
  heap << Node.new(index + 1, value)
end

heap.each do |value|
  value.parent_key = heap[value.index / 2 - 1] unless heap[value.index / 2 - 1].nil? || value.index == 1
  value.right_key = heap[value.index * 2] unless heap[value.index * 2].nil?
  value.left_key = heap[value.index * 2 - 1] unless heap[value.index * 2 - 1].nil?
end

puts heap.map(&:to_s)


