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