class HeapTree
	def initialize
		@node = []
	end

	private

	def swap(key)
		parent_key = (key - 1)/2
		if parent_key < 0 
			return nil
		end
		if @node[key] > @node[parent_key]
			@node[key] , @node[parent_key] = @node[parent_key] , @node[key]
			swap(parent_key)
		else
			return nil
		end
	end

	def insert!(num)
		@node << num
	swap(@node.length - 1)
	end

	def left(key)
		@node[2*key+1]
	end

	def right(key)
		@node[2*key+2]
	end

	# ???????????¢?´¢
	def precedingOrderSearch(key, &func)
		if @node[key]
			func.call(key, @node[key])
			precedingOrderSearch(left(key), &func)
			precedingOrderSearch(right(key), &func)
		end
	end
	# ???????????¢?´¢
	def afterLineOrderSearch(key, &func)
		if @node[key]
			afterLineOrderSearch(left(key), &func)
			afterLineOrderSearch(right(key), &func)
			func.call(key, @node[key])
		end
	end
	#???????????¢?´¢
	def centerOrderSearch(node, &func)
		if @node[key]
			centerOrderSearch(left(key), &func)
			func.call(key, @node[key])
			centerOrderSearch(right(key), &func)
		end
	end

	public

	def insert(num)
		insert!(num)
	end

	def preceding_crawl(&func) #???hoge.precedingCrawl do |key, value| ??????????????????
		precedingOrderSearch(0, &func)
	end

 # ????????????
 def after_line_crawl(&func)
 	afterLineOrderSearch(0, &func)
 end

# ????????????
def center_crawl(&func)
	centerOrderSearch(0, &func)
end

def list
	return @node
end
end


n = gets.to_i
head = HeapTree.new
gets.split.map(&:to_i).each do |v|
	head.insert(v)
end

puts head.list.join(" ")