

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
すぬけ君は 個の文字列を持っています。 番目の文字列は です。
これらの文字列を好きな順序で並べたあと、連結して つの文字列を作ることを考えます。
作った文字列に AB
という部分文字列が含まれる個数としてありうる値のうち、最大値を求めてください。
制約
- は英大文字のみからなる
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
3 ABCA XBAZ BAD
出力例 1Copy
2
- 例えば、
ABCA
,BAD
,XBAZ
の順で連結してABCABADXBAZ
を作ったとき、AB
という部分文字列は つ含まれます。
入力例 2Copy
9 BEWPVCRWH ZZNQYIJX BAVREA PA HJMYITEOX BCJHMRMNK BP QVFABZ PRGKSPUNA
出力例 2Copy
4
入力例 3Copy
7 RABYBBE JOZ BMHQUVA BPA ISU MCMABAOBHZ SZMEHMA
出力例 3Copy
4
Score : points
Problem Statement
Snuke has strings. The -th string is .
Let us concatenate these strings into one string after arranging them in some order.
Find the maximum possible number of occurrences of AB
in the resulting string.
Constraints
- consists of uppercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
3 ABCA XBAZ BAD
Sample Output 1Copy
2
For example, if we concatenate ABCA
, BAD
and XBAZ
in this order, the resulting string ABCABADXBAZ
has two occurrences of AB
.
Sample Input 2Copy
9 BEWPVCRWH ZZNQYIJX BAVREA PA HJMYITEOX BCJHMRMNK BP QVFABZ PRGKSPUNA
Sample Output 2Copy
4
Sample Input 3Copy
7 RABYBBE JOZ BMHQUVA BPA ISU MCMABAOBHZ SZMEHMA
Sample Output 3Copy
4