#C12382. Counting Occurrences of a Key in Dictionaries

    ID: 41803 Type: Default 1000ms 256MiB

Counting Occurrences of a Key in Dictionaries

Counting Occurrences of a Key in Dictionaries

You are given a list of dictionaries, where each dictionary contains string keys and integer values. Your task is to compute the total sum of the values associated with a given key across all dictionaries. If a dictionary does not contain the key, its value is considered to be 0.

Mathematically, for dictionaries (D_1, D_2, \dots, D_n) and a search key (k), you need to compute [ S = \sum_{i=1}^{n} \begin{cases} D_i(k) & \text{if } k \text{ exists in } D_i \ 0 & \text{otherwise} \end{cases} ] where (D_i(k)) is the integer value associated with key (k) in the (i^{th}) dictionary.

inputFormat

The input is read from standard input and has the following format:

  • The first line contains an integer (n) representing the number of dictionaries.
  • For each dictionary, the first line contains an integer (m) indicating the number of key-value pairs in that dictionary.
  • The next (m) lines each contain a string (the key) and an integer (the value) separated by a space.
  • The final line contains the string (k), the key to search for.

outputFormat

Output a single integer: the total sum of the values associated with the key (k) across all dictionaries. The output should be written to standard output.## sample

3
2
a 1
b 2
2
a 2
c 4
2
b 1
a 3
a
6