#include<iostream.h>
#include<sstream.h>

using namespace std;

int main() {
    string input;
    getline(cin, input);
    int t;
    istringstream iss(input);
    if (!(iss >> t) || t < 1 || t > 1e5) {
        cout << "Invalid input" << endl;
        return 0;
    }

    int stack[100];
    int top = -1;

    for (int i = 0; i < t; i++) {
        getline(cin, input);
        istringstream command(input);
        string op;
        command >> op;

        if (op == "push") {
            int x;
            if (command >> x && top < 99) {
                stack[++top] = x;
            }
        } else if (op == "pop") {
            if (top == -1) {
                cout << "Stack is empty" << endl;
            } else {
                cout << stack[top--] << endl;
            }
        } else if (op == "display") {
            if (top == -1) {
                cout << "Stack is empty" << endl;
            } else {
                for (int j = top; j >= 0; j--) {
                    cout << stack[j] << " ";
                }
                cout << endl;
            }
        }
    }

    return 0;
}