Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-brauzer-tarixi

Browser history

Easy 1000 ms 128 MB 31%
Share

A browser is open on the page home. It receives $n$ commands:

  • visit p — go to page $p$; after that the forward history is erased;
  • back — return to the previous page (if there is nowhere to return, nothing changes);
  • forward — go again to the page left by back (if there is no such page, nothing changes).

After each command, print which page is open in the browser.

Two stacks: pages for going back and forward, the open page highlighted in the middle

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains one command.

Output

$n$ lines — the name of the open page after each command.

Note

$1 \le n \le 10^{5}$
a page name consists of $1$ to $10$ lowercase Latin letters

Examples

Input #1
7
visit algor
visit masala
back
back
back
forward
visit kontest
Output #1
algor
masala
algor
home
home
algor
kontest
Input #2
2
back
forward
Output #2
home
home

Sign in to submit a solution

Signing up is free and takes a minute.