#K77722. Hierarchical File Storage Commands

    ID: 34928 Type: Default 1000ms 256MiB

Hierarchical File Storage Commands

Hierarchical File Storage Commands

You are given a series of commands to manage a hierarchical file storage system. There are three types of commands:

1. ADD_FOLDER <parent_folder> <folder_id>: Add a new subfolder with identifier folder_id under an existing parent_folder.

2. ADD_FILE <folder_id> <file_id> <size>: Add a file with identifier file_id and size size to the folder folder_id.

3. QUERY <folder_id>: Compute the total size of the folder folder_id. The total size is defined as (S = \sum_{f \in files}\text{size}(f) + \sum_{s \in subfolders} S(s)).

Your program should read the commands from standard input and, for every QUERY command, output the computed total size to standard output.

inputFormat

The input is given as multiple lines from standard input. The first line contains an integer n indicating the total number of lines that follow. Each of the subsequent n lines contains one command in one of the following formats:

- ADD_FOLDER <parent_folder> <folder_id>
- ADD_FILE <folder_id> <file_id> <size>
- QUERY <folder_id>

Any line that does not match these commands should be ignored.

outputFormat

For each QUERY command, print the total size of the specified folder on a new line to standard output.## sample

8
ADD_FOLDER root documents
ADD_FILE documents file1 1000
ADD_FOLDER documents projects
ADD_FILE projects file2 3000
ADD_FOLDER root music
ADD_FILE music file3 2000
QUERY root
QUERY music
6000

2000

</p>