#include<stdio.h>
#include<stdlib.h>
#define max 100
int top=0;
int stack[max];
void push(int n)
{
    if(top-1==max)
    {
        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);
        }
        else
        {
            if(!strcmp("POP",operation)
            {
                pop();
            }
            else
            {
                if(!strcmp("DISPLAY",operation))
                {
                    disp();
                }
                else
                {
                    if(!strcmp("PEEK",operation))
                    {
                        printf("\n%d ",satck[top]);
                    }
                    else
                    {
                        printf("Invalid input");
                        return 0;
                    }
                }
            }

        }
    }
    
}