#P2908. [USACO08OPEN] Word Power S

[USACO08OPEN] Word Power S

Description

Farmer John wants to evaluate the quality of the names of his N(1N1000)N (1 \le N \le 1000) cows. Each name is a string with no more than 1000 characters, all of which are non-blank.

He has created a set of M(1M100)M (1 \le M \le 100) 'good' strings (no longer than 30 characters and fully non-blank). If the sequence letters of a cow's name contains the letters of a 'good' string in the correct order as a subsequence (i.e., not necessarily all next to each other), the cow's name gets 1 quality point.

All strings is case-insensitive, i.e., capital letters and lower case letters are considered equivalent. For example, the name Bessie\texttt{Bessie} contains the letters of Be\texttt{Be}, sI\texttt{sI}, EE\texttt{EE}, and Es\text{Es} in the correct order, but not is\texttt{is} or eB\texttt{eB}. Help Farmer John determine the number of quality points in each of his cow's names.

Input Format

  • Line 11: Two space-separated integers: NN and MM.

  • Lines 2N+12 \sim N+1: Line i+1i+1 contains a string that is the name of the ith cow.

  • Lines N+2N+M+1N+2 \sim N+M+1: Line N+i+1N+i+1 contains the ith good string.

Output Format

  • Lines 1N+11 \sim N+1: Line i+1i+1 contains the number of quality points of the ith name.
5 3 
Bessie 
Jonathan 
Montgomery 
Alicia 
Angola 
se 
nGo 
Ont 

1 
1 
2 
0 
1 

Hint

There are 5 cows, and their names are Bessie\texttt{Bessie}, Jonathan\texttt{Jonathan}, Montgomery\texttt{Montgomery}, Alicia\texttt{Alicia}, and Angola\texttt{Angola}. The 3 good strings are se\texttt{se}, nGo\texttt{nGo}, and Ont\texttt{Ont}.

Bessie\texttt{Bessie} contains se\texttt{se}, Jonathan\texttt{Jonathan} contains Ont\texttt{Ont}, Montgomery\texttt{Montgomery} contains both nGo\texttt{nGo} and Ont\texttt{Ont}, Alicia\texttt{Alicia} contains none of the good strings, and Angola\texttt{Angola} contains nGo\texttt{nGo}.