

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
を英小文字のみからなる文字列、 を英小文字および ?
のみからなる文字列とします。
に含まれる ?
をそれぞれ適切な英小文字 つで置き換えることで、 を に一致させることができるとき、「 は から作れる」と言います。
例えば、a??d
からは abcd
や addd
を作れますが bcdd
を作ることはできません。
英小文字のみからなる 個の文字列 が入力として与えられます。
これらの長さはすべて です。すなわち、 です。
文字列 として、英小文字および ?
からなる長さ の文字列であって ?
をちょうど 個含むものを任意に選びます。
「 のうち、 から作れるものの個数」としてありえる最大値を出力してください。
制約
- は整数
- はそれぞれ英小文字のみからなる長さ の文字列
- は相異なる。
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
5 4 2 aabc bbaa abbc cccc acba
出力例 1Copy
3
a?b?
とすると、 aabc
, abbc
, acba
の つを から作れます。
このとき「 のうち、 から作れるものの個数」は であり、これがあり得る最大値となります。
より、 は ?
をちょうど 個含むように選ばれなければならないことに注意してください。
入力例 2Copy
5 4 4 aabc bbaa abbc cccc acba
出力例 2Copy
5
????
とすると、 のすべてを作れます。
入力例 3Copy
5 4 0 aabc bbaa abbc cccc acba
出力例 3Copy
1
Score : points
Problem Statement
Let be a string consisting of lowercase English letters and be a string consisting of lowercase English letters and ?
.
is said to be obtainable from when one can replace each occurrence of ?
in with some lowercase English letter so that equals .
For example, abcd
and addd
are obtainable from a??d
, while bcdd
is not.
You are given strings consisting of lowercase English letters.
All of these strings have a length of : .
A string of length consisting of lowercase English letters is arbitrarily chosen so that it contains exactly ?
s.
Find the maximum possible number of strings among that are obtainable from .
Constraints
- , , and are integers.
- Each of is a string of length consisting of lowercase English letters.
- are distinct.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
5 4 2 aabc bbaa abbc cccc acba
Sample Output 1Copy
3
If we let a?b?
, then aabc
, abbc
, and acba
are obtainable from .
Here, three of the strings are obtainable from , which is the maximum possible number.
Note that , so must be chosen to contain exactly two ?
s.
Sample Input 2Copy
5 4 4 aabc bbaa abbc cccc acba
Sample Output 2Copy
5
If we let ????
, all of are obtainable from .
Sample Input 3Copy
5 4 0 aabc bbaa abbc cccc acba
Sample Output 3Copy
1