L - Collecting T Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 6

注意

この問題に対する言及は、2020/12/27 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

長さ N の文字列 S と、長さ 3 の文字列 T が与えられます。
あなたは以下の操作を繰り返すことができます。

  • S の中の連続する 3 文字であって T と一致するものを選び、その 3 文字を S から消す (消した後、残っている文字は連結される)

最大で何回操作することができますか?

制約

  • 1 \le N \le 100
  • S は英小文字からなる長さ N の文字列
  • T は英小文字からなる長さ 3 の文字列

入力

入力は以下の形式で標準入力から与えられる。

N
S
T

出力

最大の操作回数を出力せよ。


入力例 1

7
adbabcd
abc

出力例 1

1

S4 文字目から 6 文字目までが T に一致するのでこれを消すことができます。
これ以上操作することはできないので、答えは 1 です。


入力例 2

6
ababaa
aba

出力例 2

2

まず、S3 文字目から 5 文字目までが T に一致するので、これを消すことができます。
Saba となったので、S の全体が T に一致し、もう一度操作ができます。
よって、答えは 2 です。


入力例 3

6
zzzzzz
abc

出力例 3

0

全く操作できない可能性もあります。

Score : 6 points

Warning

Do not make any mention of this problem until December 27, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Given are a string S of length N and a string T of length 3.
You can repeatedly do the following operation:

  • Choose three consecutive characters in S that coincide with T and remove those characters from S. (The remaining parts get concatenated.)

What is the maximum number of operations that can be done?

Constraints

  • 1 \le N \le 100
  • S is a string of length N consisting of lowercase English letters.
  • T is a string of length 3 consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S
T

Output

Print the maximum number of operations that can be done.


Sample Input 1

7
adbabcd
abc

Sample Output 1

1

The 4-th through 6-th characters of S coincide with T, so we can erase them.
We cannot do anything more, so the answer is 1.


Sample Input 2

6
ababaa
aba

Sample Output 2

2

First, the 3-rd through 5-th characters of S coincide with T, so we can erase them.
S becomes aba, which coincides with T and can be erased again.
Thus, the answer is 2.


Sample Input 3

6
zzzzzz
abc

Sample Output 3

0

Sometimes, we can do nothing.