import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        while (n-- > 0) {
            int op = in.nextInt();
            switch (op) {
                case 1:
                    int x = in.nextInt();
                    queue.offer(x);
                    break;

                case 2:
                    if (!queue.isEmpty())
                        System.out.println(queue.peek());
                    break;

                case 3:
                    if(!queue.isEmpty())
                        queue.poll();
                    break;
            }
        }
    }
}