#include<stdio.h>
#include<string.h>
#define 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");
        return;
    }
    top--;
}

void peek(){
    if(top==-1){
        printf("Stack Underflow");
    printf("%d ",stack[top]);
}

void display(){
    if(top==-1){
        printf("Stack Underflow");
        return;
    }
    for(int i=0;i<=top;i++){
        printf("%d ",stack[i]);
    }
    printf("\n");
}

int main(){
    int n char str[20];
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;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();
        }
        else{
            printf("Invalid input");
            return 0;
        }
    }
    return 0;
}