#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int size=5,top=-1;
int arr[101];
int isEmpty(){
  if(top==-1){
    return-1;
}
else{
    return 0;
}
}
int isFull(){
    if(top==size-1){
        return-1;
    }else{
        return arr[top];
    }
}
int peek(){
    if(isEmpty()){
    return-1;
    }else{
        return arr[top];
    }
}
void push(int num){
    if(isFull()){
        printf("Stack Underflow");
        
    }else{
        arr[++top]=num;
    }
}
void pop(){
    if(isEmpty()){
        printf("Stack Underflow");
        
    }else{
        arr[top--];
    }
}
void traversal(){
    for(int i=0;i<=top;i++){
        printf("%d ",arr[i]);
    }
    printf("\n");
    
    }
    int main(){
        char choice[101];
        int num,n,i;
        scanf("%d",&n);
        if(n<0){
            printf("Invalid input");
            return 0;
        }
        for(i=0;i<n;i++){
            scanf("%s",choice);
            if(strcmp(choice,"PUSH") ==0){
                scanf("%d,&num");
                push(num);
            }else if(strcmp(choice,"POP" )==0){
                pop();
            }else if(strcmp(choice,"DISPLAY")==0){
                traversal();
            }else if(strcmp(choice,"PEEK")==0){
                printf("%d",peek());
                
            }else{
                printf("Invalid input");
            }
        }
    }