// editor1
#include<stdio.h>
#include<string.h>
#define max 100
int stack[100];
int top =-1;
int size = max;
void push(int x,int size){
    if(top==size-1 ){
        printf("Stack overflow");
        return;
    }
    stack[++top]=x;
}
 ///////pop///////////////
 void pop(){
     if(top == -1){
         printf("Stack underflow");
         return;
     }
 
     top --;
 }
 
////////display////////////
void display(){
    if(top == -1){
        printf("Stack Underflow");
    }
    for (int i = 0; i<=top ; i++) {
        printf("%d ",stack[i]);
    
    }
}

////////////peek///////////
void peek(){
    if(top == -1){
        printf("Stack Underflow");
        return;
    }
printf("%d",stack[top]);
printf("\n");

    
}


int main(){
    int n;
    char str[20];
    scanf("%d",&n);
    for(int i =0;i<n;i++){
        scanf("%s",str);
            if(strcmp(str,"PUSH")==0){
                int x;
                scanf("%d",&x);
                push(x,size);
            }
            else if(strcmp(str,"POP")==0){
                pop();
                
            }
        else if(strcmp(str,"PEEK")==0){
            printf("\n")
            peek();
            
        }
         else if(strcmp(str,"DISPLAY")==0){
            display();
            
        }
         else {
            printf("Invalid input");
            return 0;
         }
        
    }
    return 0;
}