Designing an operating system

Linus Torvalds, the creator of the Linux operating system, has decided to trust you with the maintenance of the codebase for the operating system. Yet, as you like to experiment, you have decided to rewrite some of the most popular commands and deploy them to production.
notion image
This week you’re rewriting the pwd (print working directory) and the cd (change directory) commands. You would like to have those commands working based on the user input:
  1. If the user inputs pwd - the program should print the current working directory
  1. If the user inputs cd folder - the program should move to that folder:
      • If the folder is .. - it means that the program should move to the parent directory. So, if we’re at directory /usr/local/bin/, the program should move to /usr/local/.
      • If the folder is . - it means that the program should stay in the current directory.
      • If the folder starts with /, it means that the program should change the absolute path of the directory - not the relative. So, if we’re at directory /usr/local/bin/, and the input was cd /dev, the program should move to /dev/.
      • If the folder is a name (Latin letters or numbers) - the program should move to that directory relative to the current one. So, if we’re at directory /usr/local/bin/, and the input was cd ../lib, the program should move to /usr/local/lib/.
The program is initiated at the location / (which is the root of the file system).

Input

The first line of the input contains a single integer n (1 ≀ n ≀ 100) the number of commands.
The next n lines contain the commands. It’s guaranteed that the length of each command does not exceed 200 characters.

Output

The programs should print the results for all the pwd commands each on a separate line.

Examples

Input
Output
5 pwd cd usr/local/bin cd .. pwd cd /dev
/ /usr/local/
7 pwd cd /home/anna pwd cd .. pwd cd anna/../bob pwd
/ /home/anna/ /home/ /home/bob/
4 cd /usr/local pwd cd ../usr/local pwd
/usr/local/ /usr/usr/local/
Β 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue