#include<stdio.h>
#include<stdlib.h>
#define max 100
int stack[max];
int top=0;
void push(int n)
{
    if(top-1==max)
    {
        printf("Stack is empty");
        return;
    }
    stack[top++]=n;
}
void pop()
{
    if(top<0)
    {
        printf("Underflow");
        return;
    }
    int val=stack[top--];
    top--;
}
void display()
{
    for(int i=0;i<top;i++)
    {
        printf("%d ",stack[i]);
    }
}
int main()
{
    int n,x;
    scanf("%d\n",&n);
    char operation [20];
    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))
            {
                display();
            }
            else
            {
                if(!strcmp("PEEK",operation))
                {
                    printf("\n%d ",stack[top]);
                }
                else{
                    printf("Invalid input");
                    return 0;
                }
            }
        }
    }
}