QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 64 MB Puntuación total: 20

#23784. IOIOI

Estadísticas

Problem

For an integer $n$ ($1 \le n$), the string formed by alternating $n+1$ 'I's and $n$ 'O's starting with 'I' is called $P_n$. Here, 'I' and 'O' are uppercase English letters.

  • $P_1$: IOI
  • $P_2$: IOIOI
  • $P_3$: IOIOIOI
  • $P_n$: IOIOIO $\cdots$ OI ($n$ 'O's)

Figure 1-1: Definition of the string $P_n$ for an integer $n$ ($1 \le n$)

Given an integer $n$ and a string $s$ consisting only of 'I' and 'O', write a program that outputs how many places in the string $s$ contain the string $P_n$ as a contiguous substring.

Input

The input consists of $3$ lines: - The $1$st line contains an integer $n$ ($1 \le n \le 1000000$). - The $2$nd line contains an integer $m$ ($1 \le m \le 1000000$). Here $m$ represents the number of characters in the string $s$. - The $3$rd line contains the string $s$, which consists only of 'I' and 'O'.

In all test data, $2n + 1 \le m$ holds. Also, for $50\%$ of the score, $n \le 100$ and $m \le 10000$ hold.

Output

Output a single line containing an integer representing how many places in the string $s$ contain the string $P_n$. If $P_n$ is not contained in $s$ at all, output $0$.

Sample 1

1
13
OOIOIOIOIIOII
4

Sample 2

2
13
OOIOIOIOIIOII
2

Sample Explanation

When the integer $n$ is $1$ and the string $s$ is OOIOIOIOIIOII, the string $P_1$, which is IOI, is contained in $4$ places as shown in Figure 1-2 below, so the integer to output is $4$.

OOIOIOIOIIOII
  ^^^
    ^^^
      ^^^
         ^^^

Figure 1-2: For Sample 1, the string $P_1$ is contained in $4$ places

When the integer $n$ is $2$ and the string $s$ is OOIOIOIOIIOII, the string $P_2$, which is IOIOI, is contained in $2$ places as shown in Figure 1-3 below, so the integer to output is $2$.

OOIOIOIOIIOII
  ^^^^^
    ^^^^^

Figure 1-3: For Sample 2, the string $P_2$ is contained in $2$ places

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.