int main()
{
    //#ifdef _DEBUG
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    //#endif
    cin >>n;
    for(int i=0;i<n;i++)
    {
        int x=read_int(),y;
        switch(x)
        {
        case 1:
            y=read_int();
            q.push(y);
            break;
        case 2:
            cout <<q.top()<<endl;
            break;
        case 3:
            q.pop();
            break;
        }
    }
    return 0;
}
inline int dijkstra()
{
	memset(d,0x7f,sizeof(d));
	d[s]=0;
	q.push(make_pair(d[s],s));
	while(!q.empty())
	{
		pii u=q.top();q.pop();
		int x=u.second;
		if(d[x]!=u.first)continue;
		if(x==t)break;
		for(int i=point[x];i!=-1;i=edges[i].next)
		if(d[edges[i].v]>d[x]+edges[i].val){
			d[edges[i].v]=d[x]+edges[i].val;
			q.push(make_pair(d[edges[i].v],edges[i].v));
		}
	}
	return d[t];
}