A freight yard keeps a manifest of the containers currently on site. Each entry lists three tags for a container, always in the same order: its cargo category, its finish code, and its serial code. A yard inspector wants to know how many containers have one particular tag field equal to a specific value — for instance, how many containers have finish code "blue". Given the manifest and the inspector's query (which field to check, and what value it must equal), count how many containers satisfy the query.
Line 1: two space-separated tokens — a field name that is exactly one of "category", "finish", or "code", followed by a target value (a single token, no embedded whitespace) to match against that field. Line 2: a single integer N — the number of containers in the manifest. Next N lines: each contains three space-separated tokens — that container's category, finish, and code, in that order.
Print a single integer: the number of containers whose specified field equals the target value exactly (case-sensitive, exact string match — not a substring match).
1 <= N <= 10^4 Every token (each manifest field value, the field name, and the target value) consists of 1 to 15 characters drawn from lowercase English letters and digits only, with no internal whitespace. The field name on line 1 is guaranteed to be exactly one of "category", "finish", "code".
Example 1
Input
finish blue 4 metal blue c1 plastic blue c2 metal red c3 wood blue c4
Expected
3
Explanation
The query asks for containers whose finish equals "blue". Three rows (metal blue c1, plastic blue c2, wood blue c4) have finish "blue"; the row "metal red c3" has finish "red" and does not count. The answer is 3.
Example 2
Input
code c3 3 metal blue c1 plastic green c3 wood blue c3
Expected
2
Explanation
The query asks for containers whose code equals "c3". Two rows (plastic green c3, wood blue c3) have code "c3"; the row "metal blue c1" has code "c1" and does not count. The answer is 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →