Problem1023--Biggest subset of strings

1023: Biggest subset of strings

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Given a set of strings whose size is S, each string only contains char 'A' or 'B' (no lower case). Given two positive integer M and N, please

find the maximum subset of strings such that the total number of char 'A' in the subset is less than or equals to M and the total number of char 'B' is less than or equals to N.

For this problem, just output the size of the subset. ( for this problem, S <= 25 )

Input

The first line contains integer M N and S
the following S lines, each one contains one string with 'A' and 'B'

Output

One integer which is the size of the biggest subset.

Sample Input Copy

7 3 6
A
B
AAABBB
AB
BBA
BA

Sample Output Copy

4

HINT

In the example, we can make the subset of {A, B, AB, BA}, the total number of A is 3 and the total number of B is 3. therefore, the output is 4 which is the size of the set.

Source/Category