const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

// 使用数组模拟最小堆
const heap = [];

// 堆操作函数,没办法,js没有提供最小堆的标准库,只能现场手写
function heappush(value) {
    heap.push(value);
    let index = heap.length - 1;
    // 上浮调整
    while (index > 0) {
        const parentIndex = Math.floor((index - 1) / 2);
        if (heap[parentIndex] <= heap[index]) break;
        [heap[parentIndex], heap[index]] = [heap[index], heap[parentIndex]];
        index = parentIndex;
    }
}

function heappop() {
    if (heap.length === 0) return;
    const min = heap[0];
    const last = heap.pop();
    if (heap.length > 0) {
        heap[0] = last;
        // 下沉调整
        let index = 0;
        while (true) {
            const leftChild = 2 * index + 1;
            const rightChild = 2 * index + 2;
            let smallest = index;
            
            if (leftChild < heap.length && heap[leftChild] < heap[smallest]) {
                smallest = leftChild;
            }
            if (rightChild < heap.length && heap[rightChild] < heap[smallest]) {
                smallest = rightChild;
            }
            if (smallest === index) break;
            
            [heap[index], heap[smallest]] = [heap[smallest], heap[index]];
            index = smallest;
        }
    }
    return min;
}

(async function () {
    const N = parseInt(await readline());
    for (let i = 0; i < N; i++) {
        const line = await readline();
        const parts = line.split(/\s+/);
        const op = parts[0];
        
        switch (op) {
            case "1": {
                const x = parseInt(parts[1]);
                heappush(x);
                break;
            }
            case "2": {
                console.log(heap[0]);
                break;
            }
            case "3": {
                heappop();
                break;
            }
        }
    }
    rl.close();
})();