This page is still under construction.

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

Window Switching

Interview

Time limit2sMemory limit1024 MB

Summary
Simulate a circular list of running applications, inserting new ones at the front and rotating on each Alt+Tab, then print each window that becomes active.
Level

Medium4 of 10

Topics
Simulation, Array, Implementation, Linked list
Solved
No attempts yet

Problem

When a user works in the Windows operating system, several applications are often running. Each application runs in its own window. To switch between windows, the user presses <<Alt+Tab>>. This combination activates the window the user was working in before moving to the currently active window.

To switch to another window, the user can press <<Alt>> and then, without releasing it, press <<Tab>> several times. To determine which window becomes active, use the following model. Suppose nn applications are running. The operating system arranges the applications in a list ordered by decreasing time of last activity. That is, the application whose window is currently active is first in the list, the application whose window was active before that is second, and so on.

If the user presses <<Alt>> and then, without releasing it, presses <<Tab>> kk times, the window of the application at position (k mod n)+1(k \bmod n) +1 in the list becomes active. Here a mod ba \bmod b is the remainder when aa is divided by bb. In other words, the operating system treats the list as circular, going from the last element back to the first.

When a new application starts, it is added to the front of the list.

A sequence of user actions is given, where each action is either starting an application or switching between windows. Output the order in which the user worked with the applications.

Input

The first line of the input file contains an integer nn, the number of user actions (1≤n≤10001 \le n \le 1000). The next nn lines describe the user actions.

Starting an application is described by a line <<Run <{\sl application name}>\relax>>. Here <<\relax<{\sl application name}>\relax>> is a string of at most 100 Latin letters, digits, and spaces. It is separated from the word <<Run>> by exactly one space. All application names are distinct. Uppercase and lowercase letters are considered different.

Switching between applications is described by a line <<Alt+Tab+\dots+Tab>>, where the substring <<+Tab>> is repeated exactly as many times as the user pressed <<Tab>> without releasing <<Alt>>. This count does not exceed 100.

The first command in the input file is always a <<Run>> command.

Output

Output nn lines: the names of the applications the user worked with, in the order in which their windows became active.

Examples1

  1. Example 1

    Input
    6
    Run Mozilla Firefox
    Run Free Pascal
    Alt+Tab
    Run Miranda IM
    Alt+Tab+Tab
    Alt+Tab+Tab+Tab
    
    Expected output
    Mozilla Firefox
    Free Pascal
    Mozilla Firefox
    Miranda IM
    Free Pascal
    Free Pascal