#include #include #include using namespace std; const int MAX = 1e6; int heap[MAX]; int size = 0; void bubble_up(int p){ if(p==1 or size==0) return ; if(heap[p]>heap[p/2]){ swap(heap[p],heap[p/2]); bubble_up(p/2); } } int bubble_down(int p){ if(p*2<=size and p*2+1<=size){ if(heap[p*2]>heap[p*2+1]){ swap(heap[p*2],heap[p]); return bubble_down(p*2); } else{ swap(heap[p*2+1],heap[p]); return bubble_down(p*2+1); } } else if(p*2<=size){ swap(heap[p*2],heap[p]); return bubble_down(p*2); } else{ return p; } } void add(int item){ size++; heap[size]=item; bubble_up(size); } int top(){ return heap[1]; } void pop(){ int p = bubble_down(1); swap(heap[p],heap[size]); size--; if(p!=size+1) bubble_up(p); } int main(){ int n; cin>>n; while(n--){ int item; cin>>item; add(item); } while(size){ cout<