#C5156. Total Sales Calculation
Total Sales Calculation
Total Sales Calculation
You are given a list of sales records and a product ID. Each sales record consists of a product ID and the quantity sold. Your task is to calculate the total quantity sold for the given product ID.
The input starts with an integer n which indicates the number of sales records. The following n lines each contain two integers representing a product ID and the quantity sold for that record. The last line of the input contains the product ID for which you need to calculate the total sales. Your program should output the sum of quantities for records that match the given product ID.
Formally, if the sales records are represented as tuples \((p_i, q_i)\) for \(i = 1, 2, \ldots, n\) and the given product ID is \(P\), you need to compute:
\[ \text{Total Sales} = \sum_{i=1}^{n} \mathbf{1}_{\{p_i = P\}} \times q_i, \]
where \(\mathbf{1}_{\{p_i = P\}}\) is 1 if \(p_i = P\) and 0 otherwise.
inputFormat
The first line contains an integer n representing the number of sales records.
The next n lines each contain two space-separated integers: the product ID and the quantity sold.
The final line contains a single integer P representing the product ID whose total sales are to be computed.
outputFormat
Output a single integer representing the total quantity sold for product ID P.
## sample5
1 5
2 3
1 2
3 5
1 3
1
10