#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int *heap;
int n;

void swap (int i, int j)
{
	int tmp;
	tmp = heap[i];
	heap[i] = heap[j];
	heap[j] = tmp;	
}

void heapDown(int i)
{
	int lc,rc,sc;
	if (i*2>n) return;
	
	if (i*2==n)
	{
		if (heap[i]>heap[i*2])
		{
			swap(i,i*2);
		}
		return;
	}
	
	lc = 2*i;
	rc = 2*i+1;
	
	if (heap[lc]<heap[rc])
		sc = lc;
	else
		sc = rc;
		
	if (heap[i]>heap[sc])
	{
		swap(i,sc);
		heapDown(sc);
	}
	return;
}

int deleteMin()
{
	int tmp;
	
	tmp = heap[1];
	heap[1] = heap[n];
	heapDown(1);
	n = n-1;
	return tmp;
}

void constructHeap()
{
	int i;
	for (i=n/2;i>0;i--)
		heapDown(i);	
}

int main()
{
	int tmp;	
	int i,m;
	
	printf("How many numbers are you going to enter? ");
	scanf("%d",&n);
	m = n;
	heap = (int *)malloc(sizeof(int)*(n+1));
		
	printf("Now enter %d integers line by line.\n",n);
	
	for (i=1;i<=n;i++)
	{
		scanf("%d",&(heap[i]));
	}
	
	constructHeap();
	
	for (i=0;i<m;i++)
	{
		printf("%d\n",deleteMin());
	}	
}

