2016-17 Woburn Challenge Finals Round - Junior Division

Well, this is suspicious… after a year of living in begrudging peace after having been evicted from their homeland of Scarberia, the monkeys have just intercepted a secret message from the cows. The Head Monkey is no fool – this can only mean that her long-time nemesis, Bo Vine, is looking for trouble once again!
The message is a single word, a string
The first problem is that the string has been encrypted! Fortunately,
the Head Monkey is well aware of the naive Enigmoo encryption algorithm
which Bo Vine likes to use when transmitting information. Bo Vine has
surely chosen some integral shift value hey
would get encrypted into the string jga
. Note that even Bo Vine
wouldn't have been stupid enough to choose
The second problem is that the message may have been damaged, rendering
some of its letters unreadable. If the monkeys can't identify the ?
. It's possible that
all of the letters are still readable, or none of them, or anything in
between.
The Head Monkey has dug out her comprehensive dictionary of cow words,
which contains
In test cases worth ?
.
In test cases worth another ?
.
Input Specification
The first line of input consists of two space-separated integers
The second line of input consists of the string
Output Specification
Output one line consisting of a single integer – the number of different words in the dictionary which the encrypted string might match.
Sample Input
6 7
??zz?k
attack
cattle
treats
farmer
missed
battle
sleepy
Sample Output
3
Sample Explanation
The original message might have been cattle
– if the cows had chosen
igzzrk
, which is
consistent with the message found by the monkeys.
However, the original message might've also been battle
also with
missed
with
Comments