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