#K82282. Folder Size Calculator

    ID: 35941 Type: Default 1000ms 256MiB

Folder Size Calculator

Folder Size Calculator

You are given a series of commands representing file system operations. There are three types of commands:

  • create_file filename size: Create a file named filename with size size.
  • create_folder foldername: Create a folder named foldername.
  • add_to_folder foldername item: Add an item (either a file or an existing folder) to the folder named foldername.

The size of a folder is defined as the sum of sizes of all files directly inside it as well as the sizes of files in any sub-folders (recursively). If a folder does not contain any file directly or indirectly, its size is 0.

Your task is to process a sequence of commands and print the sizes of all folders in lexicographical order (i.e. sorted by folder name). The answer should include each folder on a separate line in the format:

[ \texttt{foldername size} ]

For example, if the folder archive has a size of 300 and documents also has a size of 300, then the output should be:

archive 300
documents 300

inputFormat

The input is given via standard input (stdin). The first line contains an integer N representing the number of commands. The following N lines each contain one command as described above.

outputFormat

Output to standard output (stdout) the sizes of all folders, each on its own line. The format for each line is foldername size. The folders must be printed in lexicographical order.

## sample
8
create_file myfile1 100
create_file myfile2 200
create_folder documents
add_to_folder documents myfile1
add_to_folder documents myfile2
create_folder archive
create_file myfile3 50
add_to_folder archive documents
archive 300

documents 300

</p>