#include<stdio.h>
#include<string.h>
#define max 100
int main(){
    int q;
    scanf("%d",&q);
    if(q<0){
        printf("Invalid input");
        return 0;
    }
    int stack[max];
    int top=-1;
    char command[10];
    int value;
    for(int i=0;i<q;i++){
        scanf("%s",command);
        if(strcmp(command,"PUSH")==0){
            scanf("%d",&value);
            if(top<max-1){
                stack[++top]=value;
            }
        }
        else if(strcmp(command,"POP")==0){
            if(top==1){
                printf("stack underflow\n");
            }
            else{
                top--;
            }
        }
        else if(strcmp(command,"PEEK")==0){
            if(top==-1){
                printf("stack underflow\n");
            }
            else{
                printf("%d\n",stack[top]);
            }
        }
        else if(strcmp(command,"DISPLAY")){
            if(top==-1){
                printf("stack underflow\n");
            }
            else{
                for(int j=0;j<=top;j++){
                    printf("%d\n",stack[j]);
                }
            }
        }
        else if(strcmp(command,"PEEK")==0){
            if(top==-1){
                printf("stack underflow\n");
            }
            else{
                printf("%d\n",stack[top]);
            }
        }
        else if(strcmp(command,"DISPLAY")==0){
            if(top==-1){
                printf("stack underflow\n");
            }
            else{
                for(int j=0;j<=top;j++){
                    printf("%d\n",stack[j]);
                }
            }
        }
    }
    return 0;