#include<iostream>
#include<vector>
#include<stack>
#include<string>
using namespace std;



// Heap implementation class.
class CS240MaxHeap {

private:

 public:
    CS240MaxHeap(const int k)
        : k(k), num_items(0) {};

    
    // see the assignment description for specification of what these
    // functions do
    void insert(int a) 
    {}
    int delete_max()
    {}
    int delete_max_5() 
    {}
    void print()
    {}
    void printLeftPath()
    {}
    void printRightPath()
    {}
    int crazy_clean()
    {}
    int size()
    {}

    };
   

int main() {
    CS240MaxHeap* pq = nullptr;
    int k;
    int total_items = 0;


    while (true) {
        std::string command;
        std::cin >> command;

        if (command == "r") {  // initializes heap with the max_capacity read from the input
            std::cin >> k;

            pq = new CS240MaxHeap(k);
        }
        else if (command == "x") {  // finishes the program and cleans up
            delete pq;
            return 0;
        }
        else if (command == "i") { // inserts item read from std
            int item;
            std::cin >> item;
            pq->insert(item);
            total_items++;
        }
        else if (command == "d") {  // deletes and prints item read from std
            if (pq->size() != 0) {
                total_items--;
                std::cout << pq->delete_max() << std::endl;
            }
            else {
                std::cout << "Empty heap!" << std::endl;
            }
        }
        else if (command == "d_") {  // deletes and doesn't not print item read from std
            if (pq->size() != 0) {
                total_items--;
                pq->delete_max();
            }
            else {
                std::cout << "Empty heap!" << std::endl;
            }
        }
        else if (command == "d5") {  // deletes and prints 5th largest item
            if (pq->size() >= 5) {
                total_items--;
                cout << pq->delete_max_5() << endl;
            }
            else {
                std::cout << "Heap has less than 5 elements" << std::endl;
            }
        }
        else if (command == "d_5") {  // deletes and does not print 5th largest item
            if (pq->size() >= 5) {
                total_items--;
                pq->delete_max_5();
            }
            else {
                std::cout << "Heap has less than 5 elements" << std::endl;
            }
        }
        else if (command == "pa") { // prints the heap, including total number of items and k
            if (pq->size() != 0) {
                cout << total_items << endl;
                cout << k << endl;
                pq->print();
            }
        }
        else if (command == "pl") {  // prints the left path, including total number of items and k
            if (pq->size() != 0) {
                cout << total_items << endl;
                cout << k << endl;
                pq->printLeftPath();
            }
        }
        else if (command == "pr") {  // prints the right path,  including total number of items and k
            if (pq->size() != 0) {
                cout << total_items << endl;
                cout << k << endl;
                pq->printRightPath();
            }
        }
        else if (command == "es") {
            int sum = pq->crazy_clean();
            std::cout << sum << endl;
        }
    }
}

