#K62912. Directory Size Computation
Directory Size Computation
Directory Size Computation
You are given a JSON representation of a directory structure. Each key represents either a file name or a subdirectory name. If the value is an integer, it represents the size (in bytes) of a file; if it is a nested JSON object, it represents a subdirectory containing files and/or other subdirectories.
Your task is to compute the total size of the directory. Formally, if we denote by \(S(D)\) the total size of a directory \(D\), then
\( S(D) = \sum_{f \in files} size(f) + \sum_{d \in subdirs} S(d) \)
The input is provided as a single JSON object (read from standard input) and the output should be a single integer representing the total size in bytes (written to standard output).
inputFormat
The input consists of a single line containing a valid JSON object representing the directory structure. Each key is a string. The corresponding value is either an integer (representing file size in bytes) or another JSON object (representing a subdirectory).
Example:
{"file1.txt": 100, "subdir": {"file2.txt": 200}}
outputFormat
Output a single integer representing the total size (in bytes) of the directory.
For the above example, the output should be:
300## sample
{"file1.txt": 100, "file2.txt": 200}
300