This page is still under construction.

Parts of this page are still being built. What you see may change.

Library 2

Interview

Time limit2sMemory limit1024 MB

Summary
Process a sequence of push and pop actions on a stack of book titles, printing the title each time a READ pop occurs.
Level

Easy2 of 10

Topics
Stack, Simulation, Implementation
Solved
No attempts yet

Problem

Bitaro, who loves reading, decided to borrow books from the library. His house is small, so the floor has room for only 1 book. The ceiling is high enough, however, so he decided to stack books in this space to keep track of them.

Bitaro will now perform Q actions. The i-th action (1 ≤ i ≤ Q) is represented by a string Si. Si is either a string of lowercase English letters or READ, with the following meanings.

  • If it is a string of lowercase English letters, Bitaro borrows the book titled Si from the library and places it on top of the stack.
  • If it is READ, Bitaro reads the book on top of the stack and returns it to the library.

You want to determine which books Bitaro read and in what order.

Given the contents of the Q actions, write a program that outputs the titles of the books Bitaro read in the order he read them.

Input

The input is given from standard input in the following format.

Q
S1
S2
:
SQ

Output

For each action where Si is READ, output the title of the book Bitaro read, in order, separated by newlines to standard output.

Constraints

  • 2 ≤ Q ≤ 200 000.
  • Q is an integer.
  • Si is a string of length at least 1 and at most 10 (1 ≤ i ≤ Q).
  • Si is a string of lowercase English letters or READ (1 ≤ i ≤ Q).
  • There is at least one i (1 ≤ i ≤ Q) for which Si is READ.
  • When Si is READ, the stack always contains at least 1 book (1 ≤ i ≤ Q).

Examples2

  1. Example 1

    Input
    7
    joi
    joig
    ioi
    READ
    egoi
    READ
    READ
    
    Expected output
    ioi
    egoi
    joig
    
  2. Example 2

    Input
    20
    one
    READ
    two
    three
    four
    five
    six
    seven
    READ
    eight
    nine
    READ
    ten
    eleven
    READ
    READ
    twelve
    READ
    READ
    READ
    
    Expected output
    one
    seven
    nine
    eleven
    ten
    twelve
    eight
    six