• + 0 comments
    import java.io.*;
    import java.util.*;
    
    //Youtube : The Adarsh 1M
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            int n;
            Scanner sc = new Scanner(System.in);
            n = sc.nextInt();
            // int min = 99999;
            // int [] arr = new int[n];
            // List<Integer> arr = new ArrayList<>();
            // Set<Integer> arr = new HashSet<>();
            TreeMap<Integer, Integer> mp = new TreeMap<>();
            for(int i = 0; i < n; i++) {
                int op = sc.nextInt();
                if(op == 1) {
                    int num = sc.nextInt();
                    // arr.add(num);
                    mp.put(num, mp.getOrDefault(num, 0) + 1);
                }
                else if(op == 2){
                    int num = sc.nextInt();
                    // arr.remove(num);
                    if(mp.get(num) > 1){
                        mp.put(num, mp.get(num)-1);
                    }
                    else {
                        mp.remove(num);
                    }
                }
                else {
                    // int min = 9999;
                    // for(int lol : arr){
                    //     min = Math.min(min, lol);
                    // }
                    
                    System.out.println(mp.firstKey());
                }
            }
        }
    }