#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 100
int stack[MAX];
int top = -1;

void push(int x) {
    if (top == MAX - 1) {
        printf("Stack overflow\n");
        return;
    }
    stack[++top] = x;
}
void pop() {
    if (top == -1) {
          if (scanf("%d", &t) != 1) {
        printf("Stack is empty\n");
    } else {
        printf("%d\n", stack[top--]);
    }
}

void display() {
    if (top == -1) {
        printf("Stack is empty\n");
    } else {
        for (int i = top; i >= 0; i--) {
            printf("%d", stack[i]);
            if (i > 0) printf(" ");
        }
        printf("\n");
    }
}

int main() {
    int t;
    if (scanf("%d", &t) != 1) {
        printf("Stack is empty\n");
        return 0;
    }

    getchar(); 

    for (int i = 0; i < t; i++) {
        char command[20];
        fgets(command, sizeof(command), stdin);

        if (strncmp(command, "push", 4) == 0) {
            int x;
            if (sscanf(command + 5, "%d", &x) == 1) {
                push(x);
            }
        } else if (strncmp(command, "pop", 3) == 0) {
            pop();
        } else if (strncmp(command, "display", 7) == 0) {
            display();
           
        }
    }

    return 0;
}