#CCBOTPBA0000050. Trạm kiểm tra nhiều mức (Multi-Level Inspection Station)
Trạm kiểm tra nhiều mức (Multi-Level Inspection Station)
Multi-Level Inspection Station
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
An inspection station processes records in sequence. Each record contains a code and an integer value . A record with code passes when ; a record with code passes when . Code terminates the sequence and its record is not counted. Count the records that pass before the first code . Codes can only be , or , and a terminating record is guaranteed.
Input
A sequence of integer pairs and , separated by whitespace (pairs may be on separate lines). The sequence ends at the first pair with . The value of the terminating pair does not affect the result.
Output
Print one integer: the total number of passing records, excluding the terminating record.
Subtasks
- Subtask 1 (20%): $0\le k\le20;\ c\in\{0,1\}\text{ trước mã kết thúc};\ -10^9\le x\le10^9$.
- Subtask 2 (30%): .
- Subtask 3 (50%): $0\le k\le100000;\ c\in\{0,1,2\};\ -10^9\le x\le10^9$.
Here, is the number of records preceding the terminator. The terminating record is not included in .
Examples
Example 1
Input:
1 5
2 11
2 10
0 0
Output:
2
Explanation: (1,5) passes because , giving count 1. (2,11) fails because . (2,10) passes because , giving count 2. Code 0 stops processing, so the answer is 2.
Example 2
Input:
0 99
Output:
0
Explanation: The first code is 0, so no record is processed and the answer is 0.
Example 3
Input:
1 4
2 11
0 -10
Output:
0
Explanation: Both records before the sentinel fail. The value -10 in the terminating record is ignored.