#include <iostream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <vector>
#define maxnum 1000000000
using namespace std;

struct TwoTree
{
    int h, root;
    vector<TwoTree> tree;
    TwoTree() {}
    TwoTree(int x)
    {
        h = 0, root = x;
        tree.clear();
    }
    void operator =(const TwoTree &a)
    {
        h = a.h, root = a.root;
        tree = a.tree;
    }
    TwoTree addSubTree(TwoTree a)
    {
        TwoTree res = *this;
        res.h++;
        res.tree.push_back(a);
        return res;
    }
    TwoTree mergeTree(TwoTree A, TwoTree B)
    {
        if (A.root>B.root) return A.addSubTree(B);
        return A.addSubTree(B);
    }
};//螟ァ譬ケ譬?

struct TwoHeap
{
    int root;
    vector<TwoTree> tree;
    TwoHeap() {}
    TwoHeap(int x)
    {
        root = x;
        tree.clear();
        tree.push_back(TwoTree(x));
    }
    void clear()
    {
        root = -maxnum;
        tree.clear();
    }
    void push_back(TwoTree a)
    {
        tree.push_back(a);
    }
    int size()
    {
        return tree.size();
    }
    int top()
    {
        int res = -maxnum;
        for (int i = 0; i < tree.size(); i++) res = max(res, tree[i].root);
        return res;
    }
    TwoHeap mergeHeap(TwoHeap A, TwoHeap B)
    {
        TwoHeap res;
        res.clear();
        int head_A = 0, head_B = 0;
        while (head_A<A.size()||head_B<B.size())
        {
            if (head_B<B.size())
            {
                while (head_A<A.size()&&A.tree[head_A].h<B.tree[head_B].h)
                    res.push_back(A.tree[head_A]), head_A++;
            }
            else
            {
                while (head_A<A.size())
                    res.push_back(A.tree[head_A]), head_A++;
            }
            if (head_A<A.size())
            {
                while (head_B<B.size()&&A.tree[head_A].h>B.tree[head_B].h)
                    res.push_back(B.tree[head_B]), head_B++;
            }
            else
            {
                while (head_B<B.size())
                    res.push_back(B.tree[head_B]), head_B++;
            }
        }
    }
    TwoHeap add(int x)
    {
        TwoHeap A = *this;
        TwoHeap B = TwoHeap(x);
        return mergeHeap(A, B);
    }
};//螟ァ譬ケ蝣?

int main()
{

}