import heapq
q = int(input())
mono_queue = []
poly_queue = []
served = dict()
ans = []
count = 0
for query in range(1, q+1):
read_line = input().split(" ")
if read_line[0] == '1':
m = int(read_line[1])
count += 1
heapq.heappush(mono_queue, (count, -m))
heapq.heappush(poly_queue, (-m, count))
elif read_line[0] == '2':
next_to_serve = heapq.heappop(mono_queue)[0]
while(next_to_serve in served.keys()):
next_to_serve = heapq.heappop(mono_queue)[0]
ans.append(next_to_serve)
served[next_to_serve] = True
elif read_line[0] == '3':
next_to_serve = heapq.heappop(poly_queue)[1]
while(next_to_serve in served.keys()):
next_to_serve = heapq.heappop(poly_queue)[1]
ans.append(next_to_serve)
served[next_to_serve] = True
print(" ".join([str(x) for x in ans]))
#include <bits/stdc++.h>
#define loop(n) for(int i = 1; i <= n; i++)
#define rloop(n) for(int i = n; i >= 1; i--)
#define loop0(n) for(int i = 0; i < n; i++)
#define rloop0(n) for(int i = n-1; i >= 0; i--)
#define iloop(s,n,step) for(int i = s; i <= n; i+=step)
#define jloop(s,n,step) for(int j = s; j <= n; j+=step)
#define loopit(x) for(auto it = x.begin(); it!= x.end(); it++)
#define all(x) x.begin(),x.end()
using namespace std;
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(0);
}
bool vis[500009];
int main()
{
fast();
int tc = 1;
//cin >> tc;
while(tc--){
int n,q,x,idx=1,order=1;
cin >> n;
priority_queue<pair<int,int>> pq;
while(n--){
cin >> q;
if(q==1){
cin >> x;
pq.push({x,-idx});
idx++;
}
else if(q==2){
while(vis[order]) order++;
cout << order << ' ';
vis[order]=1;
}
else{
while(vis[-pq.top().second]) pq.pop();
x=-pq.top().second;
cout << x << ' ';
vis[x]=1;
pq.pop();
}
}
}
return 0;
}
873D - Merge Sort | 1251A - Broken Keyboard |
463B - Caisa and Pylons | 584A - Olesya and Rodion |
799A - Carrot Cakes | 1569B - Chess Tournament |
1047B - Cover Points | 1381B - Unmerge |
1256A - Payment Without Change | 908B - New Year and Buggy Bot |
979A - Pizza Pizza Pizza | 731A - Night at the Museum |
742A - Arpa’s hard exam and Mehrdad’s naive cheat | 1492A - Three swimmers |
1360E - Polygon | 1517D - Explorer Space |
1230B - Ania and Minimizing | 1201A - Important Exam |
676A - Nicholas and Permutation | 431A - Black Square |
474B - Worms | 987B - High School Become Human |
1223A - CME | 1658B - Marin and Anti-coprime Permutation |
14B - Young Photographer | 143A - Help Vasilisa the Wise 2 |
320A - Magic Numbers | 1658A - Marin and Photoshoot |
514A - Chewbaсca and Number | 382A - Ksenia and Pan Scales |