def tree(i)
  if i == 0
    if $input.size >= 2
      tree(1)
      tree(2)
    end
  else
    if $input.size >= 2*i+2
      tree(2*i+1)
      tree(2*i+2)
      swap(i)
    else
      swap(i)
    end
  end
end

def swap(i)
  parent = $input[(i-1)/2]
  child = $input[i]
  if !child.nil? && parent < child
    $input[i] = parent
    $input[(i-1)/2] = child
  end
end

def run
  a = Array.new
  while $input.size != 1
    tree(0)
    a.push($input.shift)
  end
  a.push($input.shift)
  puts " #{a.join(' ')}"
end

def main
  gets
  $input = gets.split.map(&:to_i)
  run()
end

main()