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