// editor3
#include<stdio.h>
#include<string.h>
#define MAX_SIZE 100
int main(){
    int n;
    if(scanf("%d",&n)!=1)return 0;
    if(n<0){
        printf("Invalid input\n");
        return 0;
    }
    int stack[MAX_SIZE];
    int top=-1;
    for(int i=0;i<n;i++){
        char cmd[10];
        scanf("%s",cmd);
        if(strcmp(cmd,"PUSH")==0){
            int x;
            scnaf("%d",&x);
            if(top<MAX_SIZE-1){
                stack[++top]=x;
            }
        }
        else if(strcmp(cmd,"POP")==0){
            if(top==-1){
                printf("Stack Underflow\n");
            }
            else{
                top--;
            }
        }
         else if(strcmp(cmd,"PEEK")==0){
            if(top==-1){
                printf("Stack Underflow\n");
            }
            else{
                printf("%d\n",stack[top]);
            }
        }
         else if(strcmp(cmd,"DISPLAY")==0){
            if(top==-1){
               
            }
            else{
                for(int j=0;j<=top;j++){
                    printf("%d ",stack[j]);
                } 
                printf("\n");
            }
        }
    }
    return 0;
}