20250807
/*
#include <stdio.h>
#include <string.h>
char stack[50001]= {};
int top=-1;
void push(char a)
{
top++;
stack[top]=a;
}
void pop()
{
top--;
}
int main()
{
char c[50001]= {};
scanf("%s",c);
for(int i=0; c[i]!=0; i++)
{
if(c[i]=='(')
{
push(c);
}
else if(c[i]==')')
{
pop();
if(top<-1)
{
printf("bad");
return 0;
}
}
}
// 삼항연산자 조건식?a:b
printf( top==-1 ? "good" : "bad");
return 0;
}
*/
//STL stack
#include <stdio.h>
#include <string.h>
int stack[200]={};
int ttop=-1;
void push(char a)
{
ttop++;
stack[ttop]=a;
}
void pop()
{
if(ttop>-1)
{
ttop--;
}
}
void top()
{
if(ttop==-1)
{
printf("-1\n");
}
else
{
printf("%d\n", stack[ttop]);
}
}
void size()
{
printf("%d\n", ttop+1);
}
void empty()
{
if(ttop==-1)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
int main()
{
int n;
char c[201]={};
scanf("%d",&n);
for(int i=0;i<=n;i++)
{
gets(c);
if(c[1]=='u')
{
push(c[6]-'0');
}
else if(c[0]=='p' && c[1]=='o')
{
pop();
}
else if(c[0]=='t')
{
top();
}
else if(c[0]=='s')
{
size();
}
else if(c[0]=='e')
{
empty();
}
}
return 0;
}




