{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cbr\u003eConsider an alphabet consisting of terminal characters \u0027a\u0027 and \u0027b\u0027 and non-terminal characters 1,2,...,\u003ci\u003eN\u003c/i\u003e. Each non-terminal character \u003ci\u003eK\u003c/i\u003e has a description, which is a string of terminal and non-terminal characters; the non-terminal characters in the description are less than \u003ci\u003eK\u003c/i\u003e. The description may be empty.\u003cbr\u003eYou take the string containing single non-terminal character \u003ci\u003eN\u003c/i\u003e and replace all non-terminal characters in it by their definitions until we obtain a string containing only terminal characters, which is called the final string.\u003cbr\u003eThe task is: given a nonempty string \u003ci\u003eS\u003c/i\u003e of terminal characters, determine the number of its occurences in the final string.\u003cbr\u003e\u003cdiv align\u003d\"left\" style\u003d\"margin-top: 1.0em;\"\u003e\u003cb\u003eInput\u003c/b\u003e\u003c/div\u003eThe first line of the input contains single integer \u003ci\u003eN\u003c/i\u003e (1≤ \u003ci\u003eN\u003c/i\u003e≤ 30). The second line contains string \u003ci\u003eS\u003c/i\u003e containing at most 100 characters. The rest of the input contains the non-terminal characters\u0027 descriptions. The \u003ci\u003eK\u003c/i\u003e+2-nd line (1≤ \u003ci\u003eK\u003c/i\u003e≤ \u003ci\u003eN\u003c/i\u003e) contains the description of \u003ci\u003eK\u003c/i\u003e-th character. It starts with a non-negative integer \u003ci\u003eL\u003c/i\u003e\u003csub\u003e\u003ci\u003eK\u003c/i\u003e\u003c/sub\u003e, followed by \u003ci\u003eL\u003c/i\u003e\u003csub\u003e\u003ci\u003eK\u003c/i\u003e\u003c/sub\u003e characters of the alphabet separated by spaces. The sum of all \u003ci\u003eL\u003c/i\u003e\u003csub\u003e\u003ci\u003eK\u003c/i\u003e\u003c/sub\u003e does not exceed 500.\u003cbr\u003e\u003cdiv align\u003d\"left\" style\u003d\"margin-top: 1.0em;\"\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/div\u003eThe only line of the output must contain the answer without leading zeroes.\u003cbr\u003e"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\nabb\n2 a b \n3 a 1 b\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003cbr\u003e\n Novosibirsk SU Contest #2, by Novosibirsk Team #1"}}]}