class Stack:
    def __init__(self):
        self.items = []
        self.capacity = 100

    def push(self, x):
        if len(self.items) < self.capacity:
            self.items.append(x)

    def pop(self):
        if not self.items:
            print("Stack is empty")
        else:
            print(self.items.pop())

    def display(self):
        if not self.items:
            print("Stack is empty")
        else:
            print(' '.join(map(str, self.items[::-1])))

try:
    t = int(input())
except:
    print("Invalid input")
    exit()

stack = Stack()
for _ in range(t):
    command = input().strip()
    if command.startswith("push "):
        try:
            _, x = command.split()
            x = int(x)
            stack.push(x)
        except:
            print("Invalid input")
    elif command == "pop":
        stack.pop()
    elif command == "display":
        stack.display()
    else:
        print("Invalid input")