Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2022 /round3 /second_mistake.md
wjomlex's picture
2022 Problems
f7ba5f2 verified
|
raw
history blame
2.74 kB

You, a perfect speller, have a vocabulary of (N) distinct words, (V_1, ..., V_N), each consisting of exactly (L) lowercase letters from the alphabet ({)'m', 'e', 't', 'a'(}).

Your friend, a truely terrable speler, has attempted to write (Q) of these words as (W_1, ..., W_Q), each also consisting of (L) lowercase letters from the same alphabet.

Let (S_i) be the number of words in your vocabulary that differ from (W_i) at exactly two indices. Please determine the sum (S_1 + ... + S_Q).

Constraints

(1 \le T \le 95) (1 \le N, Q \le 750{,}000) (1 \le L = |V_i| = |W_i| \le 20{,}000) ((N+Q)*L \le 15{,}000{,}000) (V_{ij} \in {)'m', 'e', 't', 'a'(}) (W_{ij} \in {)'m', 'e', 't', 'a'(}) All (V_i) in a given test case are distinct.

The sum of lengths of all strings across all cases is at most (18{,}000{,}000).

Input Format

Input begins with a single integer (T), the number of test cases. For each test case, there is first a line containing a single integer (N). Then, (N) lines follow, the (i)th of which contains the string (V_i). Then, there is a line containing a single integer (Q). Then, (Q) lines follow, the (i)th of which contains the string (W_i).

Output Format

For the (i)th test case, output a single line containing "Case #i: " followed by a single integer, the sum (S_1 + ... + S_Q).

Sample Explanation

The first case is depicted below:

{{PHOTO_ID:1332823754208247|WIDTH:500}}

The answer is (4), since:

  • (W_1) = "teammate" differs from "metamate" at three indices, so (S_1 = 0).
  • (W_2) = "meatmate" differs from "metamate" at exactly two indices, so (S_2 = 1).
  • (W_3) = "metatame" differs from "metamate" at exactly two indices, so (S_3 = 1).
  • (W_4) = "mememate" differs from "metamate" at exactly two indices, so (S_4 = 1).
  • (W_5) = "metameme" differs from "metamate" at exactly two indices, so (S_5 = 1).

In the second case, the answer is (0), since:

  • (W_1) = "tata" differs from (V_1) = "meet" at four indices, (V_2) = "emma" at three indices, and (V_3) = "tate" at only one index, so (S_1 = 0).
  • (W_2) = "maam" differs from (V_1) = "meet" at three indices, (V_2) = "emma" at four indices, and (V_3) = "tate" at three indices, so (S_2 = 0).

In the third case, the answer is (5), since:

  • (W_1) = "tam" differs from both (V_1) = "mem" and (V_3) = "mat" at exactly two indices, so (S_1 = 2).
  • (W_2) = "mat" differs from (V_1) = "mem" at exactly two indices, so (S_2 = 1).
  • (W_3) = "tea" differs from both (V_1) = "mem" and (V_2) = "met" at exactly two indices, so (S_3 = 2).