#C1261. Final Directory Size Calculation

    ID: 42056 Type: Default 1000ms 256MiB

Final Directory Size Calculation

Final Directory Size Calculation

You are given a directory identified by an integer id and its initial size. The size of a directory is defined as the sum of the sizes of all files and subdirectories directly in it. After this, n operations are performed, each representing a move operation where a file or subdirectory is moved to another directory with a specified additional size.

Your task is to compute the final size of a specified directory. Only the operations where the destination directory target_id matches the queried directory id are taken into account. The formula can be expressed in LaTeX as:

\( FinalSize = InitialSize + \sum_{i=1}^{n} \mathbf{1}_{(target_i = query)} \times size_i \)

Here, \( \mathbf{1}_{(target_i = query)} \) is an indicator function that equals 1 if the operation's target equals the queried directory, and 0 otherwise.

Process the operations sequentially and output the final size of the queried directory.

inputFormat

The input is given via standard input (stdin) with the following format:

Line 1: An integer n, the number of operations.
Line 2: Two space-separated integers: query_id and initial_size, where query_id is the id of the directory to query and initial_size is its starting size.
Next n Lines: Each contains three space-separated integers, representing an operation in the form: source_id, target_id, and size. Only operations with target_id matching query_id affect the final result.

outputFormat

Output a single integer on a single line to standard output (stdout), representing the final size of the queried directory after processing all operations.

## sample
4
1 10
3 1 5
4 1 3
3 2 5
4 3 3
18

</p>