{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e Consider 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.\u003c/p\u003e \n\u003cp\u003e \u003cbr\u003e You 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\u003e \u003cbr\u003e The task is: given a nonempty string \u003ci\u003eS\u003c/i\u003e of terminal characters, determine the number of its \u003cspan\u003e\u003cspan\u003eoccurences\u003c/span\u003e\u003c/span\u003e in the final string.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e The first line of the input contains single integer \u003ci\u003eN\u003c/i\u003e (\u003cspan\u003e\u003cspan\u003e1≤\u003c/span\u003e\u003c/span\u003e \u003cspan\u003e\u003cspan\u003e\u003ci\u003eN\u003c/i\u003e≤\u003c/span\u003e\u003c/span\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+\u003cspan\u003e2-nd\u003c/span\u003e line (\u003cspan\u003e\u003cspan\u003e1≤\u003c/span\u003e\u003c/span\u003e \u003cspan\u003e\u003ci\u003eK\u003c/i\u003e≤\u003c/span\u003e \u003ci\u003eN\u003c/i\u003e) contains the description of \u003cspan\u003e\u003ci\u003eK\u003c/i\u003e-th\u003c/span\u003e character. It starts with a non-negative integer \u003cspan\u003e\u003cspan\u003e\u003ci\u003eL\u003c/i\u003e\u003csub\u003e\u003ci\u003eK\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e, followed by \u003cspan\u003e\u003cspan\u003e\u003ci\u003eL\u003c/i\u003e\u003csub\u003e\u003ci\u003eK\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e characters of the alphabet separated by spaces. The sum of all \u003cspan\u003e\u003cspan\u003e\u003ci\u003eL\u003c/i\u003e\u003csub\u003e\u003ci\u003eK\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e\u003c/span\u003e does not exceed 500.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e The only line of the output must contain the answer without leading zeroes.\u003c/p\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e\r\n2\r\n\u003cspan\u003eabb\u003c/span\u003e\r\n2 a b \r\n3 a 1 b\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e\r\n1\u003c/pre\u003e"}}]}