Under construction

Still being built. Things may change

Streaming Services

Interview

Time limit2sMemory limit512 MB

Summary
Given the daily release days for two streaming services, find the fewest K-day subscriptions needed so every day has a subscribed service releasing an episode.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy
Solved
No attempts yet

Problem

Last year, you finally became a cord-cutter and cancelled your TV subscription to avoid the annoying ads. This was a relief. Suddenly, you could watch TV whenever you wanted, rather than when the channels decided. This happiness did not last long. The streaming services quickly adopted the old "one episode a week" model that TV channels used, and lunch conversations at work began to revolve around the episodes released the previous day.

A streaming service works like this. On certain days, a service releases exactly one new episode of a TV show. Every day, you need to watch an episode released that day so you can join the lunch conversations the next day.

Since your favourite streaming service may skip some days, you plan to use two streaming services instead. On any given day, you can buy a subscription to a service you do not currently subscribe to. A subscription lasts KK days, and during each of those days, you can watch episodes on the service you just subscribed to. Even if you already have an active subscription for a service, you may buy a subscription to the other service.

Given the dates when each service releases a new episode over the next NN days, determine the total number of subscriptions you need to buy so that every day you have an active subscription to a service that releases a new episode.

Input

The first line contains NN, the number of days the release schedule covers, and KK, the number of days each subscription lasts (1≤K≤N1 \le K \le N). The next line is a string of NN characters, each of which is 1, 2, or B. The ii-th character tells you whether on day ii only the first service (1) releases a new episode, only the second service (2) does, or both (B) do.

Output

Output a single integer: the number of times you need to purchase a streaming service subscription so that you can watch a newly released episode each day.

Constraints

N≤400 000N \le 400\,000

Examples2

  1. Example 1

    Input
    3 2
    121
    
    Expected output
    3
    
  2. Example 2

    Input
    8 3
    1B21B212
    
    Expected output
    5