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