Spelling with Chemistry
시간 제한1초메모리 제한2048 MB
길이 1에서 5까지인 기호 200개 이하가 주어질 때, 단어 20개 이하를 그 기호들의 나열로 나누는 경우의 수를 각각 센다.
문제
Each element on the periodic table has a one or two letter symbol. These symbols can be combined to spell words, and many times there are multiple ways of spelling a word using different combinations of symbols. Can you determine how many different ways a word can be spelled using the symbols?
For example, the word "bacon" can be spelled different ways:
- Barium, Cobalt, Nitrogen: BaCoN
- Boron, Actinium, Oxygen, Nitrogen: BAcON
- Barium, Carbon, Oxygen, Nitrogen: BaCON
However, your friend from another universe wants to spell words with the elements found there, which are different than the elements in our universe. So, your input will include the set of symbols in the periodic table for that particular universe. In this other universe, they don't follow the same naming convention that we do, so the provided symbols could be up to letters in length.
입력
The first line of input will contain an integer (), the number of symbols in that universe.
The next lines will contain a single unique symbol, each between and letters in length.
The next line of input will contain an integer (), the number of words for which you should determine how many ways they can be spelled.
The next lines each contain a single word, each between and letters in length, containing only lowercase letters.
출력
Output a total of lines, each line indicating the number of ways that the corresponding input word can be spelled using the symbols in the periodic table for that universe. If a word is impossible to spell, output a on that line.