SDE Path

Heap Sort

Medium

Heap Sort

Sort an array in-place using the heap sort algorithm.

Input format

The first line contains N. The second line contains N space-separated integers.

Output format

Print the array sorted in ascending order using heap sort.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
5
4 10 3 5 1
Expected output
1 3 4 5 10
Example 2
Input
3
1 2 3
Expected output
1 2 3