// editor2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#define MAX 100
int main()
{
    int n;
    if(scanf("%d",&n)!=1)
    {
        printf("Invalid input\n");
        return 0;
    }
    if(n<1 ||n>100)
    {
        printf("Invalid input\n");
        return 0;
    }
    int stack[MAX];
    int top=-1;
    char command[20];
    for(int i=0;i<n;i++)
    {
        scanf("%s",command);
        if(strcmp(command,"push")==0)
        {
            int x;
            if(scanf("%d",&x)!=1)
            {
                printf("Invalid input\n");
                return 0;
            }
            if(top==max-1)
            {
                printf("Stack overflow\n");
            }
            else
            {
                stack[++top]=x;
            }
        }
        else if(strcmp(command,"pop")==0)
        {
            if(top==-1)
            {
                printf("Stack is empty\n");
            }
            else
            {
                top--;
                printf("%d\n",stack[top]);
            }
        }
        else if(strcmp(command,"display")==0)
        {
            if(top==-1)
            {
                printf("Stack is empty");
            }
            else
            {
                for(int j=top;j>=0;j--)
                {
                    printf("%d",j);
                }
            }
        }
        else
        {
            printf("Invalid input\n");
            return 0;
        }
    }
    return 0;
}