#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class heap
{
private:
	vector<int> storage;
public:
	heap(){}
	heap(const vector<int>& vec):storage(vec){make_heap(storage.begin(),storage.end());}
	void push(int n)
	{
		storage.push_back(n);
		push_heap(storage.begin(),storage.end());
	}
	int pop()
	{
		pop_heap(storage.begin(),storage.end());
		int high=storage.back();
		storage.pop_back();
		return high;
	}
	bool isempty()const
	{
		return storage.empty();
	}
	void print()const
	{
		for (auto e:storage)
			cout <<e <<" ";
	}
};

int main() {
	vector <int> test = {1,4,2,5,7,3};
	heap h=test;
	h.print();cout <<endl;
	h.push(4);
	h.print();cout <<endl;
	h.push(9);
	h.print();
	while (!h.isempty())
	{
		cout <<"pop " <<h.pop() <<endl;
		h.print();
	}
	return 0;
}