~/algor $ cat problems/stack-brauzer-tarixi
Browser history
Easy
1000 ms
128 MB
31%
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 byback(if there is no such page, nothing changes).
After each command, print which page is open in the browser.
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