#K74967. Constructing a Max-Heap

    ID: 34315 Type: Default 1000ms 256MiB

Constructing a Max-Heap

Constructing a Max-Heap

You are given an unsorted array of integers. Your task is to transform this array into a max-heap. In a max-heap, every node satisfies the condition that its value is greater than or equal to the values of its children. This means that if an element is at index \(i\), then for its left child at index \(2i+1\) and right child at index \(2i+2\), the following properties hold:

\( a[i] \geq a[2i+1] \) (if the left child exists) and \( a[i] \geq a[2i+2] \) (if the right child exists).

Your implementation should convert the given array into a max-heap using the standard heapify procedure.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output the resulting max-heap as a single line of \(n\) space-separated integers.

## sample
6
3 1 5 7 2 4
7 3 5 1 2 4