def heap_sort(a,n)
	i = (n - 1) / 2
	while i >= 0
		max_heap(a,i,n-1)
		i -= 1
	end
	i = n - 1
	while i >= 0
		tmp = a[0]
		a[0] = a[i]
		a[i] = tmp
		i -= 1
		max_heap(a,0,i)
	end
	a
end
def max_heap(a,root,bottom_index)
	child_index = root*2+1
	parent_value = a[root]
	while child_index <= bottom_index
		child_index = child_index + 1 if child_index < bottom_index && a[child_index] > a[child_index+1]
		if parent_value < a[child_index]
			break
		elsif parent_value >= a[child_index]
			a[(child_index-1)/2] = a[child_index]
			child_index = child_index * 2 + 1
		end
	end
	a[(child_index-1)/2] = parent_value
end



a = gets.to_i
b = gets.split.map(&:to_i)
puts " " + heap_sort(b,a).join(" ")