#C5749. Final Character Count

    ID: 49432 Type: Default 1000ms 256MiB

Final Character Count

Final Character Count

You are given a text file that is initially empty. Throughout the day, a series of operations is performed on the file. Each operation is recorded as a tuple containing a timestamp, an operation type (add or delete), and the number of characters to add or delete.

The task is to determine the final character count at the end of the day. However, during processing, if the character count becomes non-positive (i.e. less than or equal to 0) at any moment, the process terminates immediately and the answer is 0.

You can represent the final count by the following formula:

$$\text{Total} = \sum_{i=1}^{n} a_i$$

where the update is stopped immediately if at some step \(Total \le 0\).

inputFormat

The first line contains an integer n, the number of operations.

The next n lines each contain an operation in the following format:

timestamp operation number

where:

  • timestamp is a string in HH:MM:SS format (this field is not used in the calculation).
  • operation is either add or delete.
  • number is an integer representing the number of characters to add or delete.

outputFormat

Output a single integer which is the final character count after processing the operations. If at any moment the character count becomes less than or equal to 0, output 0 immediately.

## sample
5
08:15:30 add 10
08:20:45 delete 5
09:10:22 add 5
10:00:00 delete 20
11:45:00 add 30
0