#include<stdio.h>
#include<stdlib.h>

int max=5;
int stack[100];
int top = -1;

void push(int value){
    if(top == max-1){
        printf("Invalid input");
    }
    else{
        stack[++top] = value;
        printf("%d ",value);
    }
}

void pop(){
    if(top == -1){
        printf("Invalid input \n");
    }
    else{
        top--;
        printf("\n");
    }
}

void peek(){
    if(top == -1){
        printf("Invalid input");
    }
    else{
        printf("%d\n",stack[top]);
    }
}
void display(){
    if(top==-1){
         printf("Invalid input");
     }
    else{
        for(int i=0; i<=top; i++){
            printf("%d",stack[i]);
        }
     }
int main(){
    int choice, value;
    while(1){
        scanf("%d",&value);
        switch(choice){
            case 1:
            scanf("PUSH %d",&value);
            push(value);
            break;
            
            case 2:
            printf("POP");
            pop();
            break;
            
            case 3:
            scanf("DISPLAY");
            display();
            break;
            
            case 4:
            scanf("PEEK");
            peek();
            break;
        }
    }
}