#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define max 7
int main (){
    int t;
    scanf("%d \n",&t);
    if(isdigit(t)!=0){
        printf("Invalid input");
    }else {
        for(int i=1; i <=t ;++i){
            char com
            scanf("%s",&com);
            if(strcmp(com,"push")==0){
                if(scanf("%d",&x)!=1){
                printf("Invalid input");
                return 0;
            }
            if(top==max-1){
                printf("Stack overflow\n");
            }else{
                stack[++top]=x;
            }
            }else if(strcmp(com,"display")==0){
                if(top == -1){
                    printf("Stack is empty\n");
                }else{
                    for(int i =top ; i<top; i--){
                        printf("%d\n",stack[top]);
                    }
                }
            }else if(strcrmp(com,"pop")==0){
                if (top==-1){
                    printf("Stack is empty\n");
                }else{
                    printf("%d \n",stack[top--]);
                }
            }else{
                printf("Invalid input\n");
                return 0;
            }
        }
    }
    return 0;
}