#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 100

int stack[MAX];
int top=-1;

void push(int x){
    if(x<0){
        printf("Invalid input\n");
        return ;
        
    }
    if(top== MAX-1){
        printf("Stack Overflow\n");
        return ;
    }
    stack[++top]=x;
}
void pop(){
    if(top==-1){
        printf("stack underflow\n");
        return ;
    }
    top--;
}
void peek(){
    if(top==-1){
        printf("Stack underflow\n");
    }
   
    printf("%d ",stack[top]);
}
void display(){
    if(top==-1){
        printf("stack underflow\n");
        return ;
    }
    for(int i=0;i<=top;i++){
        printf("%d",stack[i]);
    }
    printf("\n");
    
}
int main(){
    int q;
    scanf("%d",&q);
    getchar();
    char command[20];
    int x;
    
    for(int i=0;i<q;i++){
        scanf("%s",command);
        
        if(strcmp(command,"PUSH")==0){
            scanf("%d",x);
            push(x);
        }
        else if(strcmp(command,"POP")==0){
            pop();
        }
        else if(strcmp(command,"PEEK")==0){
            peek();
        }
        else if(strcmp(command,"DISPLAY")==0){
            display();
        }
        else{
            printf("Invalid input");
            while(getchar()!='\n');
        }
    }
    return 0;
    
}