{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eTired of using existing badly written operating systems,\n Hieu decided to write a new one. Of course, his new operating\n system will be awesome, bug-free, fast and easy to use. He has\n finished most of the work, and now he is asking you to do one\n last task: Implement a directory manager. Initially, Hieu’s\n computer directory is empty. The current directory is the root\n directory.\u003c/p\u003e\n \u003cp\u003eThe directory manager keeps the directory in a rooted-tree\n structure. In each directory, the children are sorted in\n lexicographic order.\u003c/p\u003e\n \u003ccenter\u003e\n \u003cimg src\u003d\"CDN_BASE_URL/dadf2e0852385262c77fd30bbaae93d9?v\u003d1715171319\" alt\u003d\"\\includegraphics[width\u003d0.15\\textwidth ]{E1.png}\" style\u003d\"width:15.00%\"\u003e\n \u003c/center\u003e\n \u003cp\u003eHe can do one of the following actions:\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eMKDIR \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e: create a\n child directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e inside the current directory\n where \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e is a\n string.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eIf the current directory already contains a child\n directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e, print “ERR” and do\n nothing.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eOtherwise, print “OK”\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eRM \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e: remove a\n child directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e inside the current directory\n where \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e is a\n string.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eIf there is no child directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e, print “ERR”. Otherwise,\n print “OK”.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eCD \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e: change the\n current directory to a child directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e where \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e is a string.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eIf \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e is equal\n to the string “..” and the current directory is the\n root directory, print “ERR” and do nothing.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e is equal\n to the string “..” and the current directory is not the\n root directory, then change the current directory to\n the parent directory and print “OK”.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf there is no child directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e, print “ERR” and do\n nothing.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf there is a child directory named \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e then change the current\n directory to \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e\n and print “OK”.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eSZ: Print the total size of the current directory.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eThe size of a directory is defined as \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e + the total size of its\n children.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eLS: list the child directories of the current directory\n in lexicographic order.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eIf there is no child directory, print “EMPTY”.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf the number of child directories is between\n \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e and\n \u003cspan class\u003d\"tex2jax_process\"\u003e$10$\u003c/span\u003e inclusive,\n print all its children.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf there are more than \u003cspan class\u003d\"tex2jax_process\"\u003e$10$\u003c/span\u003e child directories in the\n current directory, print the first \u003cspan class\u003d\"tex2jax_process\"\u003e$5$\u003c/span\u003e children, followed by a\n line containing only “...”, followed by the last\n \u003cspan class\u003d\"tex2jax_process\"\u003e$5$\u003c/span\u003e children.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003cp\u003eFor example, if you are at “root” directory of the\n example in Figure \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e,\n LS would print out the following:\u003c/p\u003e\n \u003cpre\u003edira\ndirb\ndirc\u003c/pre\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eTREE: list all the directories inside the current\n directory, in pre-order traversal where the children are\n visited in lexicographic order.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eIf there is no child directory, print “EMPTY” (do\n not print the current directory).\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf the number of directories (counting all\n descendants, and including the current directory) is\n between \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e and\n \u003cspan class\u003d\"tex2jax_process\"\u003e$10$\u003c/span\u003e inclusive,\n print all the directories using pre-order\n traversal.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eIf there are more than \u003cspan class\u003d\"tex2jax_process\"\u003e$10$\u003c/span\u003e directories (counting all\n descendants, and including the current directory)\n inside the current directory, instead of printing all\n the lines, only print the first \u003cspan class\u003d\"tex2jax_process\"\u003e$5$\u003c/span\u003e lines, followed by a line\n containing “...”, followed by the last \u003cspan class\u003d\"tex2jax_process\"\u003e$5$\u003c/span\u003e lines.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003cp\u003eFor example, if you are at “root” directory of the\n example in Figure \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e,\n TREE would print out the following:\u003c/p\u003e\n \u003cpre\u003eroot\ndira\na\nb\nc\ndirb\nx\ndirc\ny\u003c/pre\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eUNDO: undo the effect of the last command that satisfy\n the following three conditions. If there is no command to\n UNDO the print “ERR”. Otherwise, print “OK”.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eThe command has to be one of the following commands:\n MKDIR or RM or CD.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eThe command did not result in printing “ERR”.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eThe command has not yet been undone by any UNDO\n command.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003cp\u003eGiven a list of commands, your task is to execute those\n commands and print the output.\u003c/p\u003e\n \u003ch2\u003eInput\u003c/h2\u003e\n \u003cp\u003eThe input consists of several datasets. The first line of\n the input contains the number of datasets which is a positive\n integer and is not greater than \u003cspan class\u003d\"tex2jax_process\"\u003e$20$\u003c/span\u003e. The following lines describe the\n datasets.\u003c/p\u003e\n \u003cp\u003eEach dataset is described by the following lines:\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eThe first line contains only one integer \u003cspan class\u003d\"tex2jax_process\"\u003e$Q$\u003c/span\u003e – the number of commands.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eEach of the next \u003cspan class\u003d\"tex2jax_process\"\u003e$Q$\u003c/span\u003e lines contains one of the\n commands described above.\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eFor commands MKDIR, RM, CD: \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e can contain only lowercase\n characters (except for the case “CD ..”) and the length\n of \u003cspan class\u003d\"tex2jax_process\"\u003e$s$\u003c/span\u003e does not\n exceed \u003cspan class\u003d\"tex2jax_process\"\u003e$4$\u003c/span\u003e.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003cp\u003eEach dataset has the following constraints:\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eThe total number of commands does not exceed\n \u003cspan class\u003d\"tex2jax_process\"\u003e$10^5$\u003c/span\u003e.\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eThe total number of MKDIR and RM commands does not\n exceed \u003cspan class\u003d\"tex2jax_process\"\u003e$5\\, 000$\u003c/span\u003e.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003ch2\u003eOutput\u003c/h2\u003e\n \u003cp\u003eThe output for each dataset should be separated by an empty\n line. For each command, you need to print out exactly like the\n above explanations. The judgement of this problem is\n case-sensitive.\u003c/p\u003e\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\n22\nMKDIR dira\nCD dirb\nCD dira\nMKDIR a\nMKDIR b\nMKDIR c\nCD ..\nMKDIR dirb\nCD dirb\nMKDIR x\nCD ..\nMKDIR dirc\nCD dirc\nMKDIR y\nCD ..\nSZ\nLS\nTREE\nRM dira\nTREE\nUNDO\nTREE\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eOK\nERR\nOK\nOK\nOK\nOK\nOK\nOK\nOK\nOK\nOK\nOK\nOK\nOK\nOK\n9\ndira\ndirb\ndirc\nroot\ndira\na\nb\nc\ndirb\nx\ndirc\ny\nOK\nroot\ndirb\nx\ndirc\ny\nOK\nroot\ndira\na\nb\nc\ndirb\nx\ndirc\ny\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}