//#include <stdio.h>
//
//char arr[50005] = {};
//
//int main()
//{
// int i,top = 0,fin = 0,k = 0;
// scanf("%c",arr);
// for(i=0;i<strlen(arr);i++) //글자수 만큼 반복
// {
// if(arr[top]=='(')
// {
// arr[top]=0;
// top++;
// fin++;
// k++;
// }
// else
// {
// if(fin<0||k>=strlen(arr)) // '(' 는 fin++, ')' 는 fin++ 인데 만약 fin이 0보다 작다면 "bad"
// {
// printf("bad");
// return 0;
// }
// fin--;
// top++;
//
// }
// }
//
// for(i=0;i<50005;i++)
// {
// if(arr[i]!=0)
// {
// printf("bad");
// return 0;
// }
// }
// printf("good");
// return 0;
//}
//
//
////#include <stdio.h>
////#include <math.h>
////int main()
////{
//// double n,k;
//// scanf("%lf",&k);
//// printf("%lf",n=sqrt(k));
//// return 0;
////}
//#include<stdio.h>
//
//int main() {
// char data[100000] = {0};
// int top=0;
// int i;
//
// scanf("%s", data);
//
// for(i=0; i<strlen(data); i++) {
// if(data[i] == '(') {
// top++;
// }
// else {
// top--;
// if(top<0) {
// printf("bad");
// return 0;
// }
// }
// }
// if(top!=0) {
// printf("bad");
// }
// else {
// printf("good");
// }
//
//
//}
#include <stdio.h>
int data[500] = {};
char fin[500] = {};
int main()
{
int n,top = 0;
scanf("%d\n",&n);
for(int i=0;i<n;i++)
{
gets(fin);
if(fin[0]=='p'&&fin[1]=='u') //push()
{
data[top]=fin[7];
top++;
}
else if(fin[0]=='t') //top()
{
if(top<=0)
{
printf("-1\n");
}
else
{
printf("%d\n",data[top-1]);
}
}
else if(fin[0]=='p'&&fin[1]=='o') //pop()
{
top--;
}
else if(fin[0]=='s') //size()
{
printf("%d\n",strlen(data));
}
else if(fin[0]=='e') //empty()
{
if(strlen(data)==0)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
}
return 0;
}



