#K89192. Count Unique Serial Numbers
Count Unique Serial Numbers
Count Unique Serial Numbers
You are given a series of operations on an inventory system. Each operation involves a serial number and an operation type. The operation type 1 indicates that the serial number is added to the inventory, while the operation type 2 indicates that the serial number is removed from the inventory if it exists.
The task is to determine the number of unique serial numbers remaining in the inventory after all operations have been performed.
In other words, if we denote the inventory as a set \( S \), then for each operation:
- If the operation is 1 and the serial number is \( s \), update \( S = S \cup \{s\} \).
- If the operation is 2 and \( s \in S \), update \( S = S \setminus \{s\} \).
Finally, output the size of \( S \), which is the total number of unique serial numbers left in the inventory.
inputFormat
The input is given via stdin and has the following format:
n op1 serial1 op2 serial2 ... op_n serial_n
Where:
n
is the number of operations.- Each of the following
n
lines contains two integers separated by a space: the first integerop
represents the operation type (1 for adding and 2 for removing), and the second integerserial
represents the serial number.
outputFormat
The output is a single integer printed to stdout representing the number of unique serial numbers remaining in the inventory after all operations.
## sample6
1 1001
1 1002
2 1001
1 1003
1 1001
2 1002
2