// editor5
#include<stdio.h>
#include<string.h>

#define Max 100

int main(){
    int n,stack[Max],top=-1;
    scanf("%d",&n);
    
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    for (int i=0;i<n;i++){
        char cmd[10];
        scanf("%s",cmd);
        
        if(strcmp(cmd,"PUSH")== 0){
            int x;
            scanf("%d",&x);
            if( top == Max - 1){
                continue;
            }
            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",struct[top]);
            }
        }
        else if(strcmp(cmd,"DISPLAY")==0){
            if(top ==-1){
                printf("\n");
            }else{
                for(int j=0;j<=top;j++){
                    printf("%d ",stack[j]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}