/*#include <stdio.h>
#include <string.h>
char* mysubstr(char* str, int start, int count)
{
//Q1 char*인 이유
//Q2 s==str인 이유
*(str+start+count)='\0';
return str+start;
}
int main()
{
char s[101]={};
int sta, end;
scanf("%s", s);
scanf("%d %d", &sta, &end);
printf("%s",mysubstr(s, sta, end));
return 0;
}
*/
//stack
/*
#include <stdio.h>
#define SIZE 5
int stack[SIZE];
int top=-1; // top= 마지막으로 데이터가 들어온 위치
void push(int data)
{
top++;
stack[top]=data;
}
int pop()
{
return stack[top--];
}
int main()
{
}
#include <stdio.h>
#include <string.h>
char stack[100000]={};
int top=-1;
void push(char data)
{
top++;
stack[top]=data;
}
char pop()
{
return stack[top--];
}
int main()
{
int i;
char str[100000];
scanf("%s", str);
for (i=0;i<strlen(str);i++)
{
push(str[i]);
}
while(top!=-1) //stack에 있는 모든 원소 pop
{
printf("%c", pop());
}
return 0;
}
*//*
#include <stdio.h>
#include <string.h>
#define size 201
char start[size]={};
int top=-1;
void push(char data)
{
top++;
start[top]=data;
}
char pop()
{
//if (top%3==2)
//{
// printf(",");
// }
return start[top--];
}
int main()
{
int n,i;
char str[size];
scanf("%d", &n);
scanf("%s", str);
for (i=n-1;i>=0;i--)
{
push(str[i]);
}
while (top!=-1)
{
printf("%c", pop());
if (top%3==2)
{
printf(",");
}
}
return 0;
}*//*
#include <stdio.h>
#include <string.h>
#define size 100001
int stack[size]={};
int top=-1;
int n;
void push(int data)
{
top++;
stack[top]=data;
}
int pop()
{
if(top==-1) return 0;
return stack[top--];
}
int main()
{
int i,a,sum=0;
scanf("%d", &n);
for (i=0;i<n;i++)
{
scanf("%d",&a);
if(a==0)
{
pop();
}
else
{
push(a);
}
}
while(top!=-1)
{
sum+=pop();
}
printf("%d", sum);
return 0;
}*//*
#include <stdio.h>
#include <string.h>
#define size 50001
char stack[size]={};
int top=-1;
void push(char data)
{
top++;
stack[top]=data;
}
char pop()
{
return stack[top--];
}
int main()
{
char str[size];
int i;
scanf("%s", str);
for (i=0;i<strlen(str);i++)
{
}
}
*/
#include <stdio.h>
#include <string.h>
#define size 201
int stack[size]={};
int top=-1;
void push(int data)
{
top++;
stack[top]=data;
}
int pop()
{
return stack[top--];
}
int main()
{
char order[20];
int i,n;
scanf("%d", &n);
for (i=0;i<n;i++)
{
gets(order);
if (order[0]=='p'&&order[2]=='u')
{
push((int)order[6]);
}
else if (order[0]=='t')
{
if (top==-1)
{
printf("-1");
}
else
{
printf("%d\n", stack[top]);
}
}
else if (order[0]=='p'&&order[1]=='o')
{
pop();
}
else if (order[0]=='s')
{
printf("%d", top+1);
}
else
{
if (top==-1)
{
printf("true");
}
else
{
printf("false");
}
}
}
return 0;
}