#include<stdio.h>
#include<string.h>
int top=-1;
int stack[100];
void push(int n)
{
    if(top-1==top)
    {
        printf("Stack Overflow");
        return;
    }
    stack[top++]=n;
}
void pop()
{
    if(top<0)
    {
        printf("Stack Underflow");
        return;
    }
    int val=stack[top--];
    top--;
}
void disp()
{
    for(int i=0;i<top;i++)
    {
        printf("%d ",stack[i]);
    }
}
int main()
{
    int n,x;
    char operation[10];
    scanf("%d",&n);
    if(n<0)
    {
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%s%d",operation,&x);
        if(!strcmp("PUSH",operation))
        {
          push(x);  
        }
        if(!strcmp("POP",operation))
        {
            pop(x);
        }
        else
        {
            if(!strcmp("DISPLAY",operation))
            {
                disp();
            }
            else
            {
                if(!strcmp("PEEk",operation))
                {
                    printf("\n%d",stack[top]);
                }
                else
                {
                    printf("Invalid input");
                    return 0;
                }
            }
        }
    }
}
}