#include <stdio.h>
#include <algorithm>
using namespace std;
long long num, o, x,top;
int cnm[200009];
int push(int h)
{
cnm[top++] = h;
}
void pop()
{
if (top != 0)
{
cnm[top] = 0;
top--;
}
}
int main()
{
scanf("%lld", &num);
for (int i = 1; i <= num; i++)
{
scanf("%lld", &o);
if (o == 0)
{
scanf("%lld", &x);
push(x);
}
else if (o == 1)
pop();
else if (o == 2)
{
if (top != 0)
{
int maxx = -1;
for (int i = 0; i < top; i++)
{
maxx = max(maxx, cnm[i]);
}
if (maxx != -1)
printf("%lld\n", maxx);
}
else
printf("0\n");
}
}
}
心态爆炸