#C345. Compute Total File Size in a Directory Structure

    ID: 46878 Type: Default 1000ms 256MiB

Compute Total File Size in a Directory Structure

Compute Total File Size in a Directory Structure

You are given a file system with a root directory named main_dir. In this file system, you can add files and create subdirectories. There are two types of commands:

  1. ADD_FILE parent_directory file_name file_size: Adds a file with the specified file name and size to a given parent directory.
  2. CREATE_DIR parent_directory subdirectory_name: Creates a new subdirectory under the given parent directory.

After processing all commands, compute the total file size of all files contained within the entire directory structure (including all subdirectories, recursively). Note that files with the same name are allowed and their sizes should be summed.

The input is read from stdin and the output is written to stdout.

inputFormat

The first line contains an integer M, representing the number of commands. Each of the following M lines contains one command in one of the following formats: ADD_FILE parent_directory file_name file_size CREATE_DIR parent_directory subdirectory_name It is guaranteed that the directory main_dir exists and that all parent directories referenced in the commands exist.

outputFormat

Output a single integer which is the total file size of all files in the directory structure.## sample

0
0