This page is still under construction.

Parts of this page are still being built. What you see may change.

IOIOI

Interview

Time limit1sMemory limit256 MB

Summary
Count the occurrences of the alternating string P_N (N+1 I's and N O's) as a substring of S, counting overlaps.
Level

Medium5 of 10

Topics
String, Sliding window, Implementation, String matching
Solved
No attempts yet

Problem

Let PNP_N be the string formed from N+1N+1 copies of I and NN copies of O in which I and O alternate. That is, PNP_N starts and ends with I, with NN Os in between.

  • P1P_1 = IOI
  • P2P_2 = IOIOI
  • P3P_3 = IOIOIOI
  • PNP_N = IOIOI…OI (with NN Os)

Given a string SS consisting only of I and O and an integer NN, write a program that counts how many times PNP_N occurs in SS. Overlapping occurrences are counted separately.

Input

The first line contains the integer NN.

The second line contains MM, the length of the string SS.

The third line contains the string SS.

Output

Print, on a single line, how many times PNP_N occurs in SS.

Constraints

  • 1≤N≤1,000,0001 \le N \le 1{,}000{,}000
  • 2N+1≤M≤1,000,0002N+1 \le M \le 1{,}000{,}000
  • SS consists only of I and O.

Examples2

  1. Example 1

    Input
    1
    13
    OOIOIOIOIIOII
    
    Expected output
    4
    
  2. Example 2

    Input
    2
    13
    OOIOIOIOIIOII
    
    Expected output
    2